酶:TypeError:适配器不是构造函数 [英] enzyme: TypeError: Adapter is not a constructor

查看:209
本文介绍了酶:TypeError:适配器不是构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Hi I was trying to test the react application With enzyme, But it throws an error TypeError: Adapter is not a constructor , Any Idea

这是我的测试文件

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:适配器不是构造函数

TypeError: Adapter is not a constructor

推荐答案

使用默认导出导入模块时,我认为import *不能按预期工作,

I don't think import * works as expected when importing a module with a default export, this should work:

import Enzyme from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'

Enzyme.configure({ adapter: new Adapter() })

顺便说一句.您可以将以上内容放入文件中,并在Jest设置中引用它,这样就不必将其添加到每个测试中了:

BTW. you can put the above in a file and reference it in your Jest settings so you don't have to add this to every test:

setupFiles: ['<rootDir>/tools/jest/setup-react-adapter.js'],

这篇关于酶:TypeError:适配器不是构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆