相关疑难解决方法(0)

enzyme:TypeError:Adapter不是构造函数

嗨,我试图用酶测试反应应用程序,但它抛出一个错误TypeError:适配器不是一个构造函数 ,任何想法

这是我的测试文件

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'}
    />
  );
});
Run Code Online (Sandbox Code Playgroud)

TypeError:Adapter不是构造函数

reactjs jestjs enzyme

10
推荐指数
3
解决办法
4924
查看次数

Enzyme需要配置适配器,但没有找到

我在调用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)

javascript reactjs jestjs enzyme

9
推荐指数
1
解决办法
3353
查看次数

标签 统计

enzyme ×2

jestjs ×2

reactjs ×2

javascript ×1