嗨,我试图用酶测试反应应用程序,但它抛出一个错误TypeError:适配器不是一个构造函数 ,任何想法
这是我的测试文件
Run Code Online (Sandbox Code Playgroud)import ProductRow from '../product_row'; import React from 'react'; // import { mount } from 'enzyme'; import * as enzyme from 'enzyme'; import * as Adapter from 'enzyme-adapter-react-16'; enzyme.configure({ adapter: new Adapter() }); test('TodoComponent renders the text inside it', () => { const wrapper = enzyme.mount( <ProductRow item={{}} quickView={[]} productPage={''} count={0} numberOfColumns={0} title={'title'} taxonomies={{}} excerpt={'excerpt'} /> ); });TypeError:Adapter不是构造函数
我在调用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';
Run Code Online (Sandbox Code Playgroud)
我的setupTests.js文件看起来像这样:
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
configure({ adapter: new Adapter() });
Run Code Online (Sandbox Code Playgroud)
并在package.json中:
"jest": {
"testEnvironment": "jest-environment-jsdom-global",
"setupFiles": [ …Run Code Online (Sandbox Code Playgroud)