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
Mocking static class methods #1245
Comments
The correct assertion should be |
Sorry, that's what I meant. I typed the example in Stackoverflow directly. |
Jest resets the module registry on every call to
Simplified explanation: var A = require('A');
jest.resetModuleRegistry();
A !== require('A'); // true, A is not the exact same module as before we reset the registry. Let me know if that doesn't fix your problem. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I ran into an issue trying to mock a static class method in Jest. Is this behavior supported?
Cross-posted at http://stackoverflow.com/questions/38206478/mocking-methods-in-jest
I have a very simple unit test that looks like this:
Where Helper looks like this:
And ApiWrapper looks like this:
ApiWrapper.help() gets mocked by Jest so 'help!' never gets printed, yet the expectation in the test fails. This still fails if we rewrite ApiWrapper to just be a plain Javascript object like such:
It works, however, if we change the imports in the spec (so ApiWrapper is imported in the beforeEach), and rewrite ApiWrapper to be a Singleton class, like so:
What is it about Jest's mocking behavior that makes this happen?
The text was updated successfully, but these errors were encountered: