Adpater is undefined if imported from Typescript
sylvaindesve opened this issue · comments
Hi,
I tried to use the adapter in a Typescript environment.
My .mocharc.json
require ts-node
and my adapter setup file:
{
"recursive": true,
"require": [
"ts-node/register",
"./spec/support.ts"
]
}
My support.ts
file is:
// ./spec/support.ts
import * as Enzyme from "enzyme";
import Adapter from "@wojtekmaj/enzyme-adapter-react-17";
console.log("Adapter =", Adapter); // Adapter = undefined
Enzyme.configure({ adapter: new Adapter() });
The imported Adapter is undefined
. It works fine though in Javascript.
{
"recursive": true,
"require": [
"ts-node/register",
"./spec/support.js"
]
}
// ./spec/support.js
const Enzyme = require("enzyme");
const Adapter = require("@wojtekmaj/enzyme-adapter-react-17");
Enzyme.configure({ adapter: new Adapter() });
Does enzyme-adapter-react-16 used to work for you the same way?
I never used Enzyme before and started at React 17 from the get go.
But for curiosity I ran yarn add --dev enzyme-adapter-react-16 @types/enzyme-adapter-react-16
and it seems like the adapter isn't exported the same way. I had to import it with:
import * as Adapter from "enzyme-adapter-react-16";
Whereas the React 17 adapter has to be imported with:
import Adapter from "@wojtekmaj/enzyme-adapter-react-17";
So I think this is just a slight change in index.d.ts
to get it working.
Maybe look into https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/enzyme-adapter-react-16/index.d.ts ?
Typings are maintained by community here as I don't have knowledge in this matter. Feel free to raise PR if you know how to change it and how to test it.