我在我的单元测试中使用jest,当我的代码抛出一个意外的异常时,我有一个问题,jest不能处理它。 例如: async function func() {
throw new Error('ERROR');
}
test('test', async () => {
await func();
}); 我希望jest能告诉我哪里有异常,但我得到的结果是: TypeError: jasmine.Spec.isPendingSpecException is not a function
at returnValue.then.error
我有一个服务(在Nestjs中),我想用Jest测试函数异常。
我的服务:
class MyService{
public throwError(ms: string) {
throw new UnprocessableEntityException(ms);
}
}
我想测试一下,但我不知道怎么做。
我有两个javascript A和B函数,定义如下,并通过另一个名为API的函数公开,如下所示,我想测试函数A,看看它是否调用了B。
function A () {
B()
}
function B () {
console.log('B is called')
}
export function API (){
return {
a: A,
b: B
}
}
我尝试我的测试函数的方式如下所示,它们不起作用。
import { API } from './actions-beta'
describe('test A&
下面是一个关于如何模拟从测试文件外部调用的函数的示例。 math.js export const add = (a, b) => a + b;
export const subtract = (a, b) => b - a;
export const multiply = (a, b) => a * b;
export const divide = (a, b) => b / a; app.js import * as math from './math.js';
export const doAdd = (a, b) =&g