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.

Hello I’m getting this error when running the test with Jest. When I run my application it works correctly but in the test it fails.

Test suite failed to run

    Missing Realm constructor - please ensure RealmReact framework is included!

      at Object.<anonymous> (node_modules/realm/lib/index.js:37:11)
      at Object.<anonymous> (app/models.js:6:12)
      at Object.<anonymous> (__tests__/models/location.test.js:2:13)

This is my configuration

Package.json

{
  "name": "App",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "jest": {
    "preset": "jest-react-native"
  },
  "dependencies": {
    "react": "15.3.1",
    "react-native": "0.32.1",
    "realm": "^0.14.3"
  },
  "devDependencies": {
    "babel-jest": "^15.0.0",
    "babel-preset-react-native": "^1.9.0",
    "eslint": "^3.4.0",
    "eslint-plugin-react": "^6.2.0",
    "eslint-plugin-react-native": "^2.0.0",
    "jest": "^15.1.1",
    "jest-react-native": "^15.0.0",
    "react-test-renderer": "^15.3.1"
  }
}

app/models.js

import Realm from 'realm';
// More imported models
class Location {
  get readableLocation() {
    return `${this.city} - ${this.country} - ${this.latitude} - ${this.longitude}`;
  }
}

Location.schema = {
  name: 'Location',
  properties: {
    city: 'string',
    country: 'string',
    latitude: 'double',
    longitude: 'double'
  }
};

export default new Realm({
  schema: [Location /* More schemas */]
});


Test

jest.unmock('../../app/models');
import realm from '../../app/models';
let context = describe;
describe('Location', () => {
  context('.readableLocation', () => {

    beforeEach(() => {
      realm.write(() => {
        realm.create('Location',
          {
            city: 'Medellín',
            country: 'Colombia',
            latitude: 123,
            longitude: 1231
          }
        );
      });

    });

    it('returns the full locations with city, country, latitude, longitude', () => {
      let location = realm.objects('Location')[0];
      let expected = `${location.city} - ${location.country} - ${location.latitude} - ${location.longitude}`;
      expect(location.readableLocation).toBe(expected);
    });


  });
});

EDIT I ran rnpm link realmand added the new RealmReactPackage()to the Main application

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
fealebenpaecommented, Sep 29, 2016

Hey folks,

We’ve been super busy with the recent launch of the Realm Mobile Platform and we haven’t had the time to investigate these Jest hangs. I’ll try to make time to look into the matter as soon as I can.

2reactions
Gerharddccommented, Feb 3, 2018

This is still causing issues for me. Just importing Realm and not using it at all is enough to prevent Jest from ever finishing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

In Jest, how can I make a test fail? - Stack Overflow
Method-1. You can wrap your promise function within expect and tell jest the function should reject with the given error. If the someOperation() ......
Read more >
Troubleshooting - Jest
Use this guide to resolve issues with Jest. Tests are Failing and You Don't Know Why​. Try using the debugging support built into...
Read more >
Jest explicitly or arbitrarily force fail() a test - Code with Hugo
Output of the test run shows that if the code doens't throw, the test suite will fail, which is desired behaviour: FAIL src/fail-throws- ......
Read more >
How to debug failing tests in jest - DEV Community ‍ ‍
Quick tip for debugging failing tests with jest. If you already know why would you want to run tests with the debugger you...
Read more >
How to find the root cause of a failing test if Jest doesn't tell ...
How to find the root cause of a failing test if Jest doesn't tell you what's wrong. Debugging tests can be hard —...
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