Error on jest when I try to run the test

GeekDev

This is the error in the console: Cannot find module 'expo' from 'setup.js'.

Below is my code:

component.test.js:

import React from 'react';
import MyComponent from '../components/Component';
import renderer from 'react-test-renderer';

test('create component correctly', () =>{
   const tree = renderer.create(
       <MyComponent/>
   ).toJSON();
   expect(tree).toMatchSnapshot();
});

Component.js:

import React, { Component } from 'react';
import {Text, View } from 'react-native';

export default class MyComponent extends React.Component{
   render(){
       return(
          <View style={{flex: 1}}>
              <View style={styles.cameraContainer}>
                  <Text> Test Component </Text>
              </View>
          </View>
      );
   }
}

When I try to use npm test the error that I mentioned before appears and I already try to uninstall and re-install jest and the error keeps showing.

stone

Assuming you are using create-react-native-app, looks like this is coming from the "jest-expo" preset in the jest configuration.

Replace it with the react-native Jest preset, which is now built in to Jest:

jest.config.js:

module.exports = { preset: 'react-native' };

Or in package.json:

"jest": {
    "preset": "react-native"
  }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Jest Test logs an error when I try to use toThrow() on an Async Function (but still passes test)

Error: Unable to find an element with the text when I try a test with Jest in React

Pytest gives me an error when try to run a test

Worker not defined when I try to run mocha test

Lua: I get error when I try to run a script in Windows

Gcc throws error when I try to compile the test folder in libburn

Make file error when I try to do with linking the test file

Pygame window not responding error when i try to run a code

gettting this error when i try to run eclipse in ubuntu please help

error when i try to run app on emulator android studio

Error Twig when I try to run Symfony 3 project on server

firebase show error when i try to run functions locally

Segmentation fault error when I try to run this program

When i try to run makemigrations command in django it gave me an error

Is there a way to get rid of the syntax error when I run try and except?

When I try to run the npm in the terminal, it showing the error

This Error will be shown when I'll try to run flutter project

Error when I run auto test with browser. How run it?

When I run the code chunks everything works but when I try to Knit I get an error

Error when I run rake test in Ruby on Rails

Im having a run time Error type mismatch when i try to run sql

How to fix "Test suite failed to run" when running a test with jest

Error when i try to opendir

When I try to run my application of submition data in SQLite there is an error 1 syntax error

For loop in macro works when I step through but get run-time error '91' when I try to run it

Why do I get a NoClassDefFound error when I try to save my test plan?

WebStorm hints me the TS error (TS2705) when I use jest(ts-jest async/await test)

React App: Why I get an error when I try to run npm start script?

when i try to run my project i get the error that says no module named flask

TOP Ranking

HotTag

Archive