enzyme-context
  • Introduction
  • Getting Started
  • Motivation
  • API
  • Official Plugins
    • Redux
    • React Router (v3)
    • React Router (v4)
    • Apollo (v2)
    • Apollo (v3)
  • Authoring Plugins
    • Enzyme Context Utils
  • Contributing
Powered by GitBook
On this page
  • 1) Install
  • 2) Create mount() and shallow()
  • 3) Use the mount/shallow we just created in place of enzyme's
  • 4) Add some plugins!

Was this helpful?

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.

PreviousIntroductionNextMotivation

Last updated 6 years ago

Was this helpful?