In our tests we want to mock classes. When mocking them with the createMock function, the instanceof operator is not returning true when checking for the to be mocked class:
class Person {
name: string;
}
const myPerson = createMock<Person>();
const isOfType = myPerson instanceof Person; // is false
I'm not sure if this is a bug or not, but it prevents us from using the mock as a direct substitute, because our code depends on the instanceof operator returning true.
Workaround is possible by using Object.setPrototypeOf(myPerson, Person.prototype);.
In our tests we want to mock classes. When mocking them with the
createMockfunction, theinstanceofoperator is not returning true when checking for the to be mocked class:I'm not sure if this is a bug or not, but it prevents us from using the mock as a direct substitute, because our code depends on the
instanceofoperator returningtrue.Workaround is possible by using
Object.setPrototypeOf(myPerson, Person.prototype);.