【发布时间】:2018-06-25 01:19:32
【问题描述】:
我在调用 enzym's mount 函数时遇到问题。它说:
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';
我的setupTests.js 文件如下所示:
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
configure({ adapter: new Adapter() });
在 package.json 中:
"jest": {
"testEnvironment": "jest-environment-jsdom-global",
"setupFiles": [
"<rootDir>/jestConfigs/setupTests.js"
],
"moduleNameMapper": {
"^.+\\.(css|scss)$": "<rootDir>/jestConfigs/CSSStub.js",
"^.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/jestConfigs/fileStub.js",
"/common-mms/(.+)": "<rootDir>/App/common-mms/$1"
}
},
但问题是 - 我使用的是 react-16,而酶适配器反应 15 与我无关。即使我添加酶适配器反应 15 以防万一 - 错误仍然存在。
更新:
如果我将 setupTests.js 的内容复制到每个测试文件的开头 - 一切正常!
如果我将console.log(1) 放入 setupTests - 它实际上会打印出来!这意味着该文件实际上是在开玩笑初始化时引入的。
【问题讨论】:
-
至少请帮助我了解如何调试它
-
你有没有安装包
enzyme-adapter-react-16? -
是的,我已经安装了。现在我将更新问题 - 问题是如果我将我的配置从配置文件复制并粘贴到每个测试文件的开头 - 一切正常。
标签: javascript reactjs jestjs enzyme