我正在为 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
添加回答
举报
0/150
提交
取消