jeudi 21 mars 2019

Problems with jest using expo in react native

I'm having what should be a simple fix, but I can't find that simple fix. I installed jest-expo and I created a __test__ directory as directed. I ran npm test from both my project root and the __test__ directory, and I get the following error:

internal/modules/cjs/loader.js:605
    throw err;
    ^

Error: Cannot find module '/Users/REDACTED/Desktop/REDACTED/ShineMobileApps/node_modules/jest/bin/jest.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15)
    at Function.Module._load (internal/modules/cjs/loader.js:529:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:774:12)
    at executeUserCode (internal/bootstrap/node.js:499:15)
    at startMainThreadExecution (internal/bootstrap/node.js:436:3)
npm ERR! Test failed.  See above for more details.

There is no jest/ directory in my node_modules directory. I have attached a picture of which jest modules I have: enter image description here

Here is the code in my /__tests__/App-test.js file:

import 'react-native';
import React from 'react';
import App from '../App';
import renderer from 'react-test-renderer';
import NavigationTestUtils from 'react-navigation/NavigationTestUtils';

describe('App snapshot', () => {
  jest.useFakeTimers();
  beforeEach(() => {
    NavigationTestUtils.resetInternalState();
  });

  it('renders the loading screen', async () => {
    const tree = renderer.create(<App />).toJSON();
    expect(tree).toMatchSnapshot();
  });

  it('renders the root without loading screen', async () => {
    const tree = renderer.create(<App skipLoadingScreen />).toJSON();
    expect(tree).toMatchSnapshot();
  });
});

So my question is:

Why is my jest not working when I run NPM test?

Aucun commentaire:

Enregistrer un commentaire