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

React Native example #1175

Closed
aaronabramov opened this issue Jun 16, 2016 · 6 comments
Closed

React Native example #1175

aaronabramov opened this issue Jun 16, 2016 · 6 comments

Comments

@aaronabramov
Copy link
Contributor

we should probably add RN example to https://github.com/facebook/jest/tree/master/examples
I get asked about it a lot
cc @davidbrear

@danibrear
Copy link

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.

@cpojer
Copy link
Member

cpojer commented Jun 16, 2016

I'll focus on this next week with the release of Jest 14. We are skipping 13 because we are superstitious. cc @zpao.

@calclavia
Copy link

calclavia commented Jun 26, 2016

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)

@chrislegault
Copy link
Contributor

chrislegault commented Jul 22, 2016

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?

@cpojer
Copy link
Member

cpojer commented Jul 27, 2016

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.

@cpojer cpojer closed this as completed Jul 27, 2016
@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants