Reactjs 类型错误:适配器不是构造函数

Reactjs 类型错误:适配器不是构造函数,reactjs,jestjs,enzyme,Reactjs,Jestjs,Enzyme,嗨,我试图用酶测试react应用程序,但它抛出了一个错误类型错误:适配器不是构造函数,你知道吗 这是我的测试文件 从“../product_行”导入ProductRow; 从“React”导入React; //从“酶”导入{mount}; 从“酶”进口*作为酶; 从'enzyme-Adapter-react-16'导入*作为适配器; configure({adapter:newadapter()}); test('TodoComponent呈现其中的文本',()=>{ const wrapper

嗨,我试图用酶测试react应用程序,但它抛出了一个错误类型错误:适配器不是构造函数,你知道吗

这是我的测试文件

从“../product_行”导入ProductRow;
从“React”导入React;
//从“酶”导入{mount};
从“酶”进口*作为酶;
从'enzyme-Adapter-react-16'导入*作为适配器;
configure({adapter:newadapter()});
test('TodoComponent呈现其中的文本',()=>{
const wrapper=enzyme.mount(
);
});
TypeError:适配器不是构造函数


我认为在导入带有默认导出的模块时,
import*
不能像预期的那样工作,这应该可以工作:

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

Enzyme.configure({ adapter: new Adapter() })
顺便说一句,您可以将上述内容放在一个文件中,并在Jest设置中引用它,这样您就不必将其添加到每个测试中:

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

import { configure } from 'enzyme';
import * as ReactSixteenAdapter from 'enzyme-adapter-react-16';
const adapter = ReactSixteenAdapter as any;
configure({ adapter: new adapter.default() });

您需要像这样使用导入:

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

这样:(导入*作为适配器从…返回一条消息“TypeError:适配器不是构造函数。”

如果您在启用
esModuleInterop
选项的情况下使用Typescript,您将需要:

import { configure} from 'enzyme';
import * as ReactSixteenAdapter from 'enzyme-adapter-react-16';
configure({ adapter: new (ReactSixteenAdapter as any)() });

我使用下面的代码,并得到相同的错误。从“酶”导入酶从“酶适配器preact pure”导入适配器;configure({adapter:newadapter()});谢谢我一直在找这个
import { configure} from 'enzyme';
import * as ReactSixteenAdapter from 'enzyme-adapter-react-16';
configure({ adapter: new (ReactSixteenAdapter as any)() });