we should probably add RN example to https://github.com/facebook/jest/tree/master/examples
I get asked about it a lot
cc @davidbrear
For the sake of conversation, I've created https://github.com/DavidBrear/jest-react-native-demo which attempts to use jest, react-native-mock, and enzyme but something has been odd because shallow rendering does not create the element with any properties.
I'll focus on this next week with the release of Jest 14. We are skipping 13 because we are superstitious. cc @zpao.
Any updates on this issue? I'm having trouble with using Jest and Enzyme as well. Referring to this commit https://github.com/DavidBrear/jest-react-native-demo/commit/5cce66427ead65d168d1b6ed00f4c702b777ef42
Runtime Error
- Error: Cannot find module './package' from 'index.js'
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:197:17)
at Runtime._resolveModule (node_modules/jest-runtime/build/index.js:304:32)
at Runtime._getNormalizedModuleID (node_modules/jest-runtime/build/index.js:465:31)
at Runtime._shouldMock (node_modules/jest-runtime/build/index.js:511:27)
at Runtime.requireModuleOrMock (node_modules/jest-runtime/build/index.js:263:14)
at Object.<anonymous> (node_modules/enzyme/node_modules/cheerio/index.js:11:19)
at Runtime._execModule (node_modules/jest-runtime/build/index.js:352:17)
at Runtime.requireModule (node_modules/jest-runtime/build/index.js:202:14)
at Runtime.requireModuleOrMock (node_modules/jest-runtime/build/index.js:266:19)
at Object.<anonymous> (node_modules/enzyme/build/ReactWrapper.js:17:16)
https://github.com/astraldragon/riki
I've got a working project setup (with enzyme), but I had to put an interesting hack in place for anything using the fetch API (https://github.com/astraldragon/riki/blob/31de077b6ecbcbb0c3679d0a14676be08e08b4c0/app/actions/__tests__/library-test.js#L8. I have no clue why. I'm using the fetch-mock library. I'd appreciate any guidance.
Basically if I try to change that test file from saying fetchMock.aMock to fetchMock.mock I get this error from Jest:
Error: /riki/app/actions/__tests__/library-test.js: babel-plugin-jest-hoist: The second argument of `jest.mock` must be a function
EDIT - I found another solution for the fetch-mock library (use their get, post, etc... functions instead of the mock function). @cpojer does jest try to do something with any call to a function that is named mock?
Thank you for your patience. We launched Jest 14.0 with experimental react-native support:
Please feel free to create new issues after trying out the new integration if any issues remain.
Most helpful comment
I'll focus on this next week with the release of Jest 14. We are skipping 13 because we are superstitious. cc @zpao.