Realm Jest tests do not work with React Native
See original GitHub issueI cannot run snapshot tests because when Realm is imported along with React Native I get following error:
SyntaxError: Unexpected token import
at transformAndBuildScript (node_modules/jest-runtime/build/transform.js:284:10)
at Object.<anonymous> (node_modules/realm/lib/index.js:30:24)
This simple example shows the problem. It passes until you uncomment import 'react-native'
line
'use strict'
// import 'react-native'
import Realm from 'realm'
describe('Realm-RN', () => {
it('should pass', () => {
expect(true).toEqual(true)
})
})
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Testing - React Native SDK - MongoDB
You can test the Realm React Native SDK with popular React Native testing libraries like Jest , Jasmine , and Mocha. Tip. See...
Read more >How do i properly test my realm.io implementation in React ...
When writing tests, it's important to remember that your goal should not be to test Realm itself, it's to ensure that your components...
Read more >Testing React Native Apps - Jest
At Facebook, we use Jest to test React Native applications. Get a deeper insight into testing a working React Native app example by...
Read more >@realm/react - npm
Realm React. Build better apps, faster. Introduction. Setting up Realm in a React Native application has historically been complex.
Read more >Realm Jest tests do not work with React Native - Bountysource
Javascript Required. Kindly enable Javascript. · Realm Jest tests do not work with React Native · Updates · Content Removed.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Making this change to my (react native) project’s package.json file fixed it for me:
"jest": { "preset": "react-native", "transformIgnorePatterns": ["node_modules/(?!react-native|tcomb-form-native|apsl-react-native-button|react|realm)"] },
This was based on a message spit out by ‘npm test’ that said this was the updated version of preprocessorIgnorePatterns.
Don’t really have any understanding of what’s going on here. Just posting a “this helped me” comment.
Let me chime in with some half knowledge: Adding ‘node_modules/realm’ to
preprocessorIgnorePatterns
solved this issue for me.Example:
"preprocessorIgnorePatterns": [ "node_modules/(?!react-native|react|realm)" ]
Vague attempt of an explanation: Something goes wrong when transpiling Realm, but that step isn’t necessary and we solve the problem by skipping that step.