Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

instanceof doesn't seem to work with class mocks #969

Open
Philipp3211 opened this issue Nov 1, 2021 · 0 comments
Open

instanceof doesn't seem to work with class mocks #969

Philipp3211 opened this issue Nov 1, 2021 · 0 comments

Comments

@Philipp3211
Copy link

Philipp3211 commented Nov 1, 2021

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);.

@Philipp3211 Philipp3211 changed the title instanceof not working with a class mock instanceof seems not to work with class mocks Nov 1, 2021
@Philipp3211 Philipp3211 changed the title instanceof seems not to work with class mocks instanceof doesn't seem to work with class mocks Nov 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant