Last active
December 6, 2019 17:22
-
-
Save ObsidianCat/5825bdcdf0345177c984648e5d180a57 to your computer and use it in GitHub Desktop.
Very minimalistic enzyme test of two components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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