首页 > 解决方案 > 反应:尝试用 src/ 镜像 __tests__/

问题描述

我想让我的 __tests__/ 镜像 src/。我能够运行测试,但它们都失败了,并出现以下相同的错误:

/application/src/setup.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import Enzyme from 'enzyme';
                                                                                             ^^^^^^

    SyntaxError: Cannot use import statement outside a module

setup.js

import Enzyme from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'

Enzyme.configure({ adapter: new Adapter() })

我的项目的文件结构如下(__tests__/ mirrors src/):

application/
  __tests__/
   App.test.js
   components/
    c.test.js
  src/
   components/
    c.js
   styles/
   App.js
   jest.config.js
   setup.js

我特别不想将我的 __test__/ 移动到 src/ 并保持结构不变,感谢您的帮助!

标签: reactjstesting

解决方案


推荐阅读