es-jest
es-jest copied to clipboard
jest.mock doesn't work with es-jest
As the title says, jest.mock doesn't work with es-jest. Adding above files in this repo and running the tests fail. This totally blocks us. Can you please help?
// file myClass.ts
export default class MyClass {
doSomething() {
return 'foo'
}
}
// file test/myClass.test.ts
import MyClass from '../myClass';
jest.mock('../myClass');
const MockedMyClass = jest.mocked(MyClass, true);
// fails here on TypeError: MockedMyClass.mockImplementation is not a function
MockedMyClass.mockImplementation(() => ({
doSomething: () => 'bar',
}))
test('MyClass', () => {
const myClass = new MyClass();
expect(myClass.doSomething()).toEqual('bar')
})
This is a limitation of esbuild, I personally recommend you switch to @swc/jest to use jest.mock.