Jest Unexpected identifier: React

十年热恋 提交于 2019-12-23 10:59:40

问题


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: "test@gmail.com",
    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.


回答1:


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



来源:https://stackoverflow.com/questions/51261252/jest-unexpected-identifier-react

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!