I have a typeguard which checks the instance of a dependency.
private isObjectOfA(obj: A | B ): obj is A {
return obj instanceof A;
}
In the spec file, I have mocked the class A.
jest.mock('./my-package/a', () => {
return {
A: jest.fn().mockImplementation(() => {
return {
someMethod: jest.fn()
};
})
};
});
import { A } from './my-package/a';
Now during testing, isObjectOfA always returns false ( because in tests the instance of obj is returned as 'Object' instead of 'A'. Maybe due to the mock ??). Is there anyway to overcome this issue?
The code for the object creation looks like,
this.myObj = someCondition ? new A() : new B();