Last active
February 7, 2018 16:41
-
-
Save gauthierm/276c48f0363efaf1379fcaca1ac890ef to your computer and use it in GitHub Desktop.
React component + Jest/Enzyme test
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 MyButton from './MyButton'; | |
export default function MyComponent(props) { | |
return (<div>Hello, world! <MyButton>Click Here</MyButton></div>); | |
} |
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
/* eslint-env jest */ | |
import React from 'react'; | |
import Enzyme, { mount } from 'enzyme'; | |
import Adapter from 'enzyme-adapter-react-16'; | |
import MyComponent from './MyComponent'; | |
import MyButton from './MyButton'; | |
Enzyme.configure({ adapter: new Adapter() }); | |
test('it renders without crashing', () => { | |
mount(<MyComponent />); | |
}); | |
test('it contains a MyButton component', () => { | |
const wrapper = mount(<MyComponent />); | |
expect(wrapper.find(MyButton)).toHaveLength(1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment