Skip to content

Instantly share code, notes, and snippets.

@ObsidianCat
Last active December 6, 2019 17:22
Show Gist options
  • Save ObsidianCat/5825bdcdf0345177c984648e5d180a57 to your computer and use it in GitHub Desktop.
Save ObsidianCat/5825bdcdf0345177c984648e5d180a57 to your computer and use it in GitHub Desktop.
Very minimalistic enzyme test of two components
import React from 'react';
import { mount } from 'enzyme';
import ParentComponent from './ParentComponent';
import ChildComponent from './ChildComponent';
describe('Parent component', () => {
it('adds and removes child component from the DOM', async () => {
const wrapper = mount(<ParentComponent />);
//Find button in Parent component
wrapper
.find('button')
.filterWhere(x => x.text() === 'Parent component button')
.simulate('click');
expect(wrapper.exists(ChildComponent)).toBe(true);
//Find button deeper, in Child component
wrapper
.find('button')
.filterWhere(x => x.text() === 'Child component button')
.simulate('click');
expect(wrapper.exists(ChildComponent)).toBe(false);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment