Closed martpet closed 2 years ago
Can you use jest.mock ?
jest.mock
With this:
import { myFunc } from '~/api'; jest.mock('~/api');
I get: Cannot find module '~/api' from 'jest.setup.js'
If I change it: jest.mock('./src/api');
jest.mock('./src/api');
The error is gone, but myFunc is not mocked.
myFunc
Here is my code: https://github.com/martpet/vite-play/blob/Add-tests/src/store/features/translations/translationsThunks.test.ts
What was the issue here? @martpet
jest.mock doesn't work with ES modules, but there is now jest.unstable_mockModule which is supposed to work.
Can you use
jest.mock
?With this:
I get: Cannot find module '~/api' from 'jest.setup.js'
If I change it:
jest.mock('./src/api');
The error is gone, but
myFunc
is not mocked.Here is my code: https://github.com/martpet/vite-play/blob/Add-tests/src/store/features/translations/translationsThunks.test.ts