是否可以将 Jest 导入到一个文件中,该文件不会作为测试运行且不包含测试用例(例如,用于测试的辅助模块)?
最佳答案
是的,这是可能的。将 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
关于javascript - 将 Jest 导入常规文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56084002/