Getting Started
1) Install
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
2) Create mount() and shallow()
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({});
3) Use the mount/shallow we just created in place of enzyme's
import { mount } from 'test-utils/enzyme';
import MyComponent from './MyComponent';
describe('<MyComponent />', () => {
let wrapper;
beforeEach(() => {
// shallow()/mount() your component like usual!
wrapper = mount(<MyComponent />);
});
});
4) Add some plugins!
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.
Last updated
Was this helpful?