Jest: Can't use babel-plugin-rewire with jest: The module factory of `jest.mock()` is not allowed to reference any out-of-scope variables

Created on 5 Mar 2019  路  3Comments  路  Source: facebook/jest

Is there any way to use babel-plugin-rewire with jest? Because of babel-plugin-jest-hoist I get this error simply by adding "rewire" to the plugins in babel.config.js:

babel-plugin-jest-hoist: The module factory of `jest.mock()` is not allowed to reference any out-of-scope variables.
    Invalid variable access: _get__

To Reproduce

Check out this repo.
Run npm run jest

Bug

Most helpful comment

I need to mock an internal function of my module which I can't do with Jest. Like here: https://medium.com/@qjli/how-to-mock-specific-module-function-in-jest-715e39a391f4

All 3 comments

Is there any specific reasons for needing to use rewire? Jest has a pretty good suite of tools for mocking things out of the box

I need to mock an internal function of my module which I can't do with Jest. Like here: https://medium.com/@qjli/how-to-mock-specific-module-function-in-jest-715e39a391f4

I have the same issue. Is there anything new?

Was this page helpful?
0 / 5 - 0 ratings