Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest Unexpected identifier: React

When I try to execute a test on reactjs with jest, it always return me the error: I have correctly install Jest, I have try to remove import but it do an error with the next.

App.test.js:

import React from 'react';
import {shallow }from 'enzyme';
import renderer from 'react-test-renderer';
import ReactDOM from 'react-dom';
import App from './App.js';
import User from './Modules/User.js';

const user = {
    email: "[email protected]",
    first_name: "test",
    last_name: "test"
}

test('Users renders properly', () => {
  const wrapper = shallow("<User users={user}/>");
  const element = wrapper.find('input');
});

If it doesn't say error for import, it don't recognise shallow when I set shallow();

Feel free to ask for more detail.

like image 226
Tryliom Avatar asked Nov 08 '22 04:11

Tryliom


1 Answers

You must change jest to react-scripts test --env=jsdom in npm test

like image 83
Yeta Avatar answered Nov 15 '22 06:11

Yeta