Skip to content

Instantly share code, notes, and snippets.

@roNn23
Created July 16, 2019 11:39
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 roNn23/cc5b8a65750af3487f251174623cb672 to your computer and use it in GitHub Desktop.
Save roNn23/cc5b8a65750af3487f251174623cb672 to your computer and use it in GitHub Desktop.
React/Jest Testing #react #js #testing
// simple component test
import React from 'react';
import { shallow } from 'enzyme';
import Button from './Button';
function setupComponent (props) {
return shallow(<Button {...props} />);
}
it('should render the button', () => {
let component = setupComponent();
expect(component.find('button')).toHaveLength(1);
});
it('should call the callback when clicked', () => {
let callback = jest.fn();
let component = setupComponent({
onClick: callback
});
component.simulate('click');
expect(callback).toBeCalled();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment