Jest Tests Handling New UUID Version
See original GitHub issueThe uuid
upgrade to 8.3.2 is causing my Jest tests to fail due to the new export format for that package. I’ve tried many different combinations of using transformIgnorePatterns
to try and get Jest to transform that package however nothing seems to take. I’ve got a couple packages that use uuid
so the version used by react-tooltip
is scoped to that package, i.e.: it’s installed in node_modules/react-tooltip/node_modules/uuid
.
// In a jest config
"transformIgnorePatterns": [
"<rootDir>/node_modules/(?!(uuid|react-tooltip/node_modules/uuid))"
]
I’ve even tried using moduleNameMapper
to get Jest to use a different uuid
package but that does not take either.
// In a jest config
"moduleNameMapper": {
"^.+\/react-tooltip\/node_modules\/uuid.+$": "<rootDir>/node_modules/uuid"
}
The only thing I’ve gotten to work to fix it is to use Jest to mock the tooltip module entirely.
// In a jest test
jest.mock('react-tooltip', () => ({
ReactTooltip: () => <div>Hello I am a tooltip</div>,
}));
Perhaps there a trick to getting Jest to transform, ignore transforms, or map modules for nested package installs like this but I haven’t been able to find it.
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:10 (5 by maintainers)
Top GitHub Comments
@aedryan I was having the exact same issue but was able to resolve it in my own project using the fix discussed here. Part of the issue appears to be that the
transformIgnorePatterns
option does not work when you have a.babelrc
in your project root. It requires usingbabel.config.js
instead. From what I have read, this information is not well documented. It is also not included in the error message we have been seeing, which is unfortunate.Following the instructions at the link I posted above, I:
renamed my
.babelrc
file tobabel.config.js
and prependedmodule.exports =
to the babel config object in that file (while also changing from double to single quotes in my case)added the following to the jest config in my project’s
package.json
:This got my Jest unit tests passing successfully. I hope this info helps in your case too!
@trevrdspcdev @aedryan can you guys try again with version 4.4.2, please?