0

I have this container

import React from "react";

class App extends React.Component {
  render() {
    return (
      <div className="App">
        <input type="text" onChange={this.changeInput} />
        <button onClick={this.addItem}>Add</button>
      </div>
    );
  }
}

export default App;

Why can't I use shallow on it? My test looks like so

import App from "./index";

describe("App", function() {
  it("should render", function() {
    const wrapper = shallow(<App />);
    //expect(wrapper).toBe(1);
  });
});

The error says Enzyme expects an adapter to be configured, but found none. but I believed I've setup Enzyme correctly. I want to test whether App contain input and a button, but I'm stuck there..

demo https://codesandbox.io/s/21rz901mp0

skyboyer
  • 22,209
  • 7
  • 57
  • 64
Hoknimo
  • 533
  • 2
  • 6
  • 15
  • 1
    Possible duplicate of [Enzyme expects an adapter to be configured](https://stackoverflow.com/questions/50222545/enzyme-expects-an-adapter-to-be-configured) – Ionut Necula Dec 11 '18 at 15:13

2 Answers2

0

Just install this package enzyme-adapter-react-16, and in your tests add those two lines :

import * as Adapter from 'enzyme-adapter-react-16';
enzyme.configure({ adapter: new Adapter() });
wahdan
  • 1,208
  • 3
  • 16
  • 26
0

Create one enzyme.js file and add follwing code... And import it into test unit-test case file

import Enzyme, { configure, shallow, mount, render } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

configure({ adapter: new Adapter() });
export { shallow, mount, render };
export default Enzyme;
Anupam Maurya
  • 1,927
  • 22
  • 26