是否可以将Jest导入不会作为测试运行且不包含测试用例的文件(例如,用于测试的帮助器模块)?
1 回答

肥皂起泡泡
TA贡献1829条经验 获得超6个赞
是的,这是可能的。jest在测试环境中可以将Jest作为开发依赖项。您可以在帮助程序文件中创建模拟的Jest函数,并将其导入测试中。
测试文件:
import { exampleFunc } from '../helper';
test('exampleFunc/0', () => {
console.log(exampleFunc());
});
助手文件:
export const exampleFunc = jest.fn().mockReturnValue('mocked return');
测试运行:
$ jest
PASS __tests__/index.test.ts
✓ exampleFunc/0 (12ms)
console.log __tests__/index.test.ts:4
mocked return
添加回答
举报
0/150
提交
取消