【发布时间】:2018-03-19 12:51:48
【问题描述】:
昨天我把我的React项目升级到v16.0,但是发现Enzyme有点问题
Error:
Enzyme Internal Error: Enzyme expects an adapter to be configured, but found none. To
configure an adapter, you should call `Enzyme.configure({ adapter: new Adapter() })`
before using any of Enzyme's top level APIs, where `Adapter` is the adapter
corresponding to the library currently being tested. For example:
import Adapter from 'enzyme-adapter-react-15';
To find out more about this, see http://airbnb.io/enzyme/docs/installation/index.html
at validateAdapter (spec/components/page_components/SongListItem/index.spec.js:9:1141986)
at getAdapter (spec/components/page_components/SongListItem/index.spec.js:9:323041)
at new ReactWrapper (spec/components/page_components/SongListItem/index.spec.js:9:622193)
at mount (spec/components/page_components/SongListItem/index.spec.js:9:2025476)
at UserContext.<anonymous> (spec/components/page_components/SongListItem/index.spec.js:9:1235741)
我在官方website上找到了解决办法
// setup file
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
configure({ adapter: new Adapter() });
但是我有一个问题:酶设置文件应该写在哪里?在每个测试文件的前面?
我尝试将上述代码添加到其中一个测试文件中,但还是有问题
Internal error: attempt to prepend statements in disallowed (non-array) context at C:/Users/killer/workspace/react/NetEase-Cloud-Music-Web/spec/components/page_components/SongListItem/index.spec.js
This是我项目的地址
【问题讨论】: