代码之家  ›  专栏  ›  技术社区  ›  Tryliom

jest意外标识符:react

  •  5
  • Tryliom  · 技术社区  · 7 年前

    当我尝试对reactjs with jest执行测试时,它总是返回错误: 我已经正确地安装了jest,我已经尝试删除import,但它在下一步中会出错。

    应用测试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');
    });
    

    如果它不表示导入错误,那么当我设置shallow()时,它就不会识别shallow;

    请随时询问更多细节。

    1 回复  |  直到 7 年前
        1
  •  1
  •   Yeta    7 年前

    你必须换衣服 jest react-scripts test --env=jsdom 在里面 npm test