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

Serializer triggers that it's expecting an enzyme-adapter when it's already provided. #129

Open
Ranguro opened this issue Feb 12, 2019 · 1 comment
Labels

Comments

@Ranguro
Copy link

Ranguro commented Feb 12, 2019

Error

Enzyme Internal Error: Enzyme expects an adapter to be configured, but found none.
      To configure an adapter, you should call `Enzyme.configure({ adapter: new Adapter() })`
      before using any of Enzyme's top level APIs, where `Adapter` is the adapter
      corresponding to the library currently being tested. For example:

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

      To find out more about this, see http://airbnb.io/enzyme/docs/installation/index.html

Libraries Versions

"enzyme-to-json": "^3.3.5"
"enzyme-adapter-react-15": "^1.3.0",
"enzyme": "^3.8.0",
"react": "^15.4.0",
"react-dom": "^15.4.0",
"jest": "^19.0.2",

How to reproduce?

This is a quite clean repro-case with only the essential parts.

https://gist.github.com/Ranguro/a14b6b8e6868ff508b80f29df8a99971

I believe the problem is linked to this specific line in my package.json

    "snapshotSerializers": [
      "<rootDir>/node_modules/enzyme-to-json/serializer"
    ]

When I add this line - the Enzyme Internal Error is being thrown. If I remove it and instead- run the following, it doesn't throw the error:

https://gist.github.com/Ranguro/f318b60054f415fd2a418900c2562742

See how I added toJson from enzyme-to-json there and the test passes.

This is my setupTests.js for the enzyme adapter.

/*eslint-disable*/

var enzyme = require('enzyme');
var Adapter = require('enzyme-adapter-react-15');
enzyme.configure({ adapter: new Adapter() });

This is how I setup my setupTests.js

    "setupTestFrameworkScriptFile": "<rootDir>/config/jest/setupTests.js",

Other Comments

I tried throw new Error('fail') to check if the configurations was being run when running tests and it showed the output well.

● Test suite failed to run

    fail

      at Object.<anonymous> (config\jest\setupTests.js:6:7)
@michens
Copy link

michens commented Feb 19, 2019

I just saw the same behavior.

For me, wrappers created by render worked fine with the serializer, but ones created by mount and shallow gave the above error. In all cases, using the toJson method directly worked as expected.

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

No branches or pull requests

3 participants