Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preact support? #227

Open
JamesMcMahon opened this issue Sep 4, 2019 · 3 comments
Open

Preact support? #227

JamesMcMahon opened this issue Sep 4, 2019 · 3 comments

Comments

@JamesMcMahon
Copy link

Currently, chai-enzyme doesn't work with the Preact library.

It fails with the stack trace:

Error: Cannot find module 'react'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/Users/james/workspace/dna-info/widget/node_modules/chai-enzyme/build/reactNodeToString.js:8:14)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/Users/james/workspace/dna-info/widget/node_modules/chai-enzyme/build/assertions/contain.js:8:26)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/Users/james/workspace/dna-info/widget/node_modules/chai-enzyme/build/index.js:15:16)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/Users/james/workspace/dna-info/widget/tests/ChartComponent.spec.tsx:5:1)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Module.m._compile (/Users/james/workspace/dna-info/widget/node_modules/ts-node/src/index.ts:473:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Object.require.extensions.(anonymous function) [as .tsx] (/Users/james/workspace/dna-info/widget/node_modules/ts-node/src/index.ts:476:12)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at /Users/james/workspace/dna-info/widget/node_modules/mocha/lib/mocha.js:334:36
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (/Users/james/workspace/dna-info/widget/node_modules/mocha/lib/mocha.js:331:14)
    at Mocha.run (/Users/james/workspace/dna-info/widget/node_modules/mocha/lib/mocha.js:811:10)
    at Object.exports.singleRun (/Users/james/workspace/dna-info/widget/node_modules/mocha/lib/cli/run-helpers.js:108:16)
    at exports.runMocha (/Users/james/workspace/dna-info/widget/node_modules/mocha/lib/cli/run-helpers.js:142:13)
    at Object.exports.handler.argv [as handler] (/Users/james/workspace/dna-info/widget/node_modules/mocha/lib/cli/run.js:292:3)
    at Object.runCommand (/Users/james/workspace/dna-info/widget/node_modules/mocha/node_modules/yargs/lib/command.js:242:26)
    at Object.parseArgs [as _parseArgs] (/Users/james/workspace/dna-info/widget/node_modules/mocha/node_modules/yargs/yargs.js:1087:28)
    at Object.parse (/Users/james/workspace/dna-info/widget/node_modules/mocha/node_modules/yargs/yargs.js:566:25)
    at Object.exports.main (/Users/james/workspace/dna-info/widget/node_modules/mocha/lib/cli/cli.js:68:6)
    at Object.<anonymous> (/Users/james/workspace/dna-info/widget/node_modules/mocha/bin/mocha:154:29)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

With the issue coming from the React import in reactNodeToString.js.

I haven't looked deeply into this, but I was wondering if it was possible to decouple this library from React and be able to use a library like Preact.

@ljharb
Copy link
Member

ljharb commented Sep 4, 2019

The only way i can see that it would really be generalizeable is if it imported all react-specific things from the configured enzyme adapter - that way, a preact adapter could supply whatever functionality was needed.

@JamesMcMahon
Copy link
Author

The only way i can see that it would really be generalizeable is if it imported all react-specific things from the configured enzyme adapter - that way, a preact adapter could supply whatever functionality was needed.

Yeah, I was thinking the same. Not sure what is involved there, I need to take some time to look at how some of their other adaptors work.

Would you be open to a pull request?

BTW, the work around is to install React as a dev dependency. So far everything works when I do that.

@javidjamae
Copy link

@JamesMcMahon said:

BTW, the work around is to install React as a dev dependency. So far everything works when I do that.

I can confirm that merely adding react as a dev dependency got past this error:
yarn add react --dev

I'm not sure if there are any possible discrepancies between how react and preact might cause enzyme to render the components. This could cause some tests to be less reliable. But, at least the workaround allows me to have tests, so I can't complain too much. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants