-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
require.requireActual not returning the actual mock #1273
Comments
jest.unmock('../moduleName') should work as expected if the path to the module is the same as the import done in the code you are testing |
@vvo Here's a more specific example that did not work: My test file (I'm trying to test TwitterProtocol module):
I believe the above code is correct? |
Yes this should work, can you create a simple repository test folder on github so we can investigate? |
Thanks for opening an issue. imports in TypeScript work similarly to ES2015 – they are hoisted above all other statements. When using babel-jest, we actually hoist Here are a few ways to work around this issue:
Of course, the right way to fix this would be a plugin for typescript that hoists |
@cpojer Would such a plugin for TypeScript be difficult to make? If it's not too difficult, I can give it a shot. |
I don't know, does TypeScript have a plugin system like babel does or is the compiler still completely closed? |
@cpojer would it make sense to run |
so basically.. if you're using |
It's definitely ok if we go down this route. I wouldn't mind for everything that doesn't use babel already. At FB, we use our custom preprocessor and we need to make sure we don't double process there – what kind of escape-hatch can you think of for this use-case? To summarize:
|
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 create a simple test with Jest's default automatic mocking. I'm trying to test one of my app's modules, so I need to make sure the module I am testing is not mocked. However, using
jest.unmock('../moduleName')
did not seem to work.I also tried using
require.requireActual('../moduleName')
, which also did not work.https://facebook.github.io/jest/docs/api.html#require-requireactual-modulename
Context: Using latest TypeScript and React Native. All source and test files are written in TypeScript. Using a tsprocessor for Jest.
Printing out the module that I intend to test seems to indicate that it is mocked, even when I explicitly told it not to mock this module:
The text was updated successfully, but these errors were encountered: