Reputation: 125
I have the following error: Cannot read property 'configure' of undefined. How can I make my unit test work.
this is my unit test so far :
import React from 'react';
import { Enzyme, mount } from 'enzyme'
import layout from './layout';
import Adapter from 'enzyme-adapter-react-15';
//Unit Test V
Enzyme.configure({ adapter: new Adapter() });
describe ('layout />', () => {
it( 'should be defined ', () => {
expect(layout).toBeDefined()
})
it( 'should render ', () => {
const wrapper = mount(<layout />)
expect(wrapper).toMatchSnapshot()
})
it( 'should render class name', () => {
const wrapper = mount
(<div className = "empty-layout"/>)
expect(wrapper).toMatchSnapshot()
})
});
I expect the test to pass. Any ideas/hints or improvements that I could implement on my unit test.
Upvotes: 1
Views: 6221
Reputation: 2964
The configure
step is always done globally in a file called setupTests.js
which is usually at the root of your project:
setupTests.js
:
import {configure} from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
configure({adapter: new Adapter()});
see here: https://facebook.github.io/create-react-app/docs/running-tests#src-setuptestsjs
So create a file setupTests.js
in the root folder of your project with the provided content above and remove the line Enzyme.configure({ adapter: new Adapter() });
from your test and see if it works.
Upvotes: 2