为了账号安全,请及时绑定邮箱和手机立即绑定

将Jest导入常规文件

将Jest导入常规文件

万千封印 2021-05-14 14:15:55
是否可以将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


查看完整回答
反对 回复 2021-05-27
  • 1 回答
  • 0 关注
  • 151 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信