enzymejs/chai-enzyme

Is this library still maintained? `[import Adapter from 'enzyme-adapter-react-15';]`

developer239 opened this issue ยท 5 comments

I am upgrading large project to React 16. I have installed following dependencies:

"chai": "^4.1.2",
"chai-enzyme": "^1.0.0-beta.1",
"enzyme": "^3.0.0",
"react": "^16.0.0-0",
"react-dom": "^16.0.0-0"

This is my testConfig.js file:

var chai = require('chai');
var sinonChai = require('sinon-chai');
var chaiAsPromised = require('chai-as-promised');
var chaiEnzyme = require('chai-enzyme');

chai.use(sinonChai);
chai.use(chaiAsPromised);
chai.use(chaiEnzyme());
global.expect = chai.expect;

window.matchMedia = window.matchMedia || function() {
  return {
    matches : false,
    addListener : function() {},
    removeListener: function() {}
  };
};

But when I run my tests I am getting missing enzyme adapter 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

When I looked at your source code you don't use custom adapter anywhere except in test/support/helper?

https://github.com/producthunt/chai-enzyme/search?q=isEnzyme3&unscoped_q=isEnzyme3

What am I doing wrong? Thanks

I believe I managed to fix the issue by instantiating my own adapter:

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

I thought this should be done by chai-enzyme? Why use chai-enzyme when I still have to do all the setup manually?

It's absolutely not done by chai-enzyme; just like enzyme itself, nobody but YOU can possibly know what react version you're using.

That makes sense. Updating 300+ tests was no fun though ๐Ÿ˜„

@developer239 you should be able to do the configure in a single file, without having to touch all your other test files.

@ljharb I meant in general ๐Ÿ™‚ I had to update enzyme to version 3.x