106
rated 0 times
[
112]
[
6]
/ answers: 1 / hits: 6441
/ 4 Years ago, fri, november 20, 2020, 12:00:00
I want to have something like this:
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);
})
Is it possible to have one file where mocked functions are implemented, and then import them in multiple tests files?
More From » reactjs