I have a typescript file defined like so:
// myType.tsx
import { Foo } from 'foo';
[...]
export interface MyType extends IDisposable {
[...]
}
export abstract class MyTypeBase implements MyType {
innerFoo: Foo | null | undefined;
get foo(): Foo {
return this.innerFoo;
}
[...]
}
I am trying to test another class which depends on this MyType, and I want to mock out the foo() getter.
In my test file, once I add the following to the file:
[...]
import { MyType } from 'path/to/MyType';
[...]
jest.mock('path/to/MyType', () => {
return jest.fn().mockImplementation(() => {
return {foo: () => mockFoo}; //mockFoo is defined earlier in the file.
})
});
I get an error when running the test:
Class extends value undefined is not a constructor or null
This only occurs when I include the jest.mock(...) line.
From other questions related, I see this can be caused by circular dependencies, but I'm failing to see how that can introduced by a call to jest.mock? I can see that other breakpoints that are hit when I comment out this code are not being hit, so it appears as though adding this mock is causing my test to fail early for this reason.
Anyone come across this before?