无法配置酶适配器

时间:2019-08-19 13:13:51

标签: reactjs typescript enzyme

我正在尝试配置酶适配器进行测试。我的代码很简单:

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

enzyme.configure({adapter : new Adapter()});

我收到如下错误:

import Adapter
Cannot use 'new' with an expression whose type lacks a call or construct signature.ts(2351)
setupTests.ts(2, 1): Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead.

这可能是版本问题吗?我正在遵循2年前的react-typescript指南。

谢谢。

1 个答案:

答案 0 :(得分:1)

小错误。

已更改:

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

收件人:

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