首页 > 解决方案 > 无法配置酶适配器

问题描述

我正在尝试配置酶适配器进行测试。我的代码是这样的,非常简单:

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 指南。

谢谢。

标签: reactjstypescriptenzyme

解决方案


小错误。

改变:

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

至:

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

推荐阅读