question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Realm Jest tests do not work with React Native

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
billpattersoncommented, Jun 3, 2017

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.

0reactions
johannesschirrmeistercommented, Nov 13, 2016

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found