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

如何将全局命令添加到 Jest 中,例如 describe 和 it?

如何将全局命令添加到 Jest 中,例如 describe 和 it?

繁星淼淼 2021-06-01 14:37:15
我正在为 Jest 编写一个小测试工具(只是为了学习)。它被调用assertTruthy(msg, fn, args),需要一个消息、一个函数和参数,如果使用参数调用函数时返回的东西是真的,则应该通过,如果不是,则失败。我想将它添加到 Jest,以便您可以调用它而无需在每个环境中导入它。describe('someFn()', () => {  // like 'it', 'describe' and 'expect' it should just be available here  it('is a function', () => {    expect(typeop someFN).toEqual('Function');  });  assertTruthy('it should return true', someFn, 3, 4);});我知道 Jest 有setupFiles,setupFilesAfterEnv但我不知道如何使用它们来实现这一点。你如何向 Jest 添加命令?PS:在单个项目的基础上(在 CRA 中),我设法这样做:// in src/setupFiles.jsconst assertTruthy = // function definition ...global.assertTruthy = assertTruthy
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 366 浏览
慕课专栏
更多

添加回答

举报

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