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

Not working with Jest #9

Closed
sinedied opened this issue Dec 2, 2018 · 4 comments
Closed

Not working with Jest #9

sinedied opened this issue Dec 2, 2018 · 4 comments

Comments

@sinedied
Copy link

sinedied commented Dec 2, 2018

When running unit tests with Jest, the importFresh function does not work properly, it always returns the same (cached?) module.

Might be due to the fact that Jest patch require with its own implementation :/

@sindresorhus
Copy link
Owner

Can you try out v3.0.0? It improves the logic for finding the module to clear.

@sinedied
Copy link
Author

Just tried, same result. Jest have its own require implementation, that can also be overridden, so I'm not sure if there's anything that can be done here, unless I can force Jest to use the "real" require implementation :/

@lonix1
Copy link

lonix1 commented Jan 24, 2019

@sinedied Use jest.resetModules() before each test:

beforeEach(() => jest.resetModules());

(The implication is that you don't need this library when using Jest.)

When Jest 24 is released, there will be a way to cache bust specific modules instead of the whole thing.

@sinedied
Copy link
Author

@lonix1 That's what I ended up doing, but as Jest doesn't go through the original require, it doesn't use this lib, making the unit test somewhat useless 😞
Still, it's not directly related to this library but rather than the way Jest load modules, so I'll close the issue.

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

3 participants