猿问
将Jest导入常规文件
是否可以将Jest导入不会作为测试运行且不包含测试用例的文件(例如,用于测试的帮助器模块)?
万千封印
浏览 152
回答 1
1回答
肥皂起泡泡
是的,这是可能的。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
0
0
随时随地看视频
慕课网APP
相关分类
JavaScript
我要回答