我想要这样的东西:
mockFunctions.ts
jest.mock('../utils', () => {
return {
getNumbers: () => [1,2,3]
}
})
__tests__/test1.ts
---import from mockFunctions---
...
it('After adding another number array has more elements', () => {
const numbers = <get these numbers using mock function>
expect([...numbers, 11]).toHaveLength(4);
})
__tests__/test2.ts
---import from mockFunctions---
...
it('After removing a number, array has less elements', () => {
const numbers = <get these numbers using mock function>
expect(numbers.filter(x => x>1)).toHaveLength(2);
})
是否可以在一个文件中实现模拟功能,然后将它们导入多个测试文件中?