Skip to content

Instantly share code, notes, and snippets.

@gauthierm
Last active February 7, 2018 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gauthierm/276c48f0363efaf1379fcaca1ac890ef to your computer and use it in GitHub Desktop.
Save gauthierm/276c48f0363efaf1379fcaca1ac890ef to your computer and use it in GitHub Desktop.
React component + Jest/Enzyme test
import React from 'react';
import MyButton from './MyButton';
export default function MyComponent(props) {
return (<div>Hello, world! <MyButton>Click Here</MyButton></div>);
}
/* 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