Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Adpater is undefined if imported from Typescript #10

Closed
sylvaindesve opened this issue Feb 22, 2021 · 3 comments · Fixed by #11
Closed

Adpater is undefined if imported from Typescript #10

sylvaindesve opened this issue Feb 22, 2021 · 3 comments · Fixed by #11
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@sylvaindesve
Copy link
Contributor

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.tsfile 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() });
@wojtekmaj
Copy link
Owner

Does enzyme-adapter-react-16 used to work for you the same way?

@sylvaindesve
Copy link
Contributor Author

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 ?

@wojtekmaj
Copy link
Owner

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.

@wojtekmaj wojtekmaj added bug Something isn't working help wanted Extra attention is needed labels Mar 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants