Enzyme Context has peer dependencies on react
and enzyme
. Make sure they are installed and set up correctly before proceeding.
Enzyme Context loves yarn
:
$> yarn add -D enzyme-context
But npm
is fine too:
$> npm install --dev enzyme-context
At TrialSpark, we do this in a module called test-utils/enzyme
, but you can put yours wherever you like:
import { createMount, createShallow } from 'enzyme-context';
export const mount = createMount({});
export const shallow = createShallow({});
import { mount } from 'test-utils/enzyme';
import MyComponent from './MyComponent';
describe('<MyComponent />', () => {
let wrapper;
beforeEach(() => {
// shallow()/mount() your component like usual!
wrapper = mount(<MyComponent />);
});
});
The mount
/shallow
we created in step two doesn't really do anything that enzyme doesn't already do out-of-the-box. The next thing you should do is install some plugins.