Gop*_*pan 10 reactjs jestjs enzyme
嗨,我试图用酶测试反应应用程序,但它抛出一个错误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不是构造函数
And*_*rle 33
我不认为import *
在导入具有默认导出的模块时按预期工作,这应该工作:
import Enzyme from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
Enzyme.configure({ adapter: new Adapter() })
Run Code Online (Sandbox Code Playgroud)
BTW.您可以将上述文件放在一个文件中并在Jest设置中引用它,这样您就不必将其添加到每个测试中:
setupFiles: ['<rootDir>/tools/jest/setup-react-adapter.js'],
Run Code Online (Sandbox Code Playgroud)
小智 9
对于打字稿:
import { configure } from 'enzyme';
import * as ReactSixteenAdapter from 'enzyme-adapter-react-16';
const adapter = ReactSixteenAdapter as any;
configure({ adapter: new adapter.default() });
Run Code Online (Sandbox Code Playgroud)
小智 8
您需要像这样使用导入:
import Adapter from 'enzyme-adapter-react-16';
Run Code Online (Sandbox Code Playgroud)
这样:(import * as Adapter from ...)返回消息“TypeError: Adapter is not a constructor”。
归档时间: |
|
查看次数: |
4924 次 |
最近记录: |