Skip to content

Instantly share code, notes, and snippets.

@ErrorPro
Created May 16, 2018 20:37
Show Gist options
  • Select an option

  • Save ErrorPro/fc486cb98765dbd1a5f6ca52f98176d1 to your computer and use it in GitHub Desktop.

Select an option

Save ErrorPro/fc486cb98765dbd1a5f6ca52f98176d1 to your computer and use it in GitHub Desktop.
import React from 'react';
import Button from './Button';
import renderer from 'react-test-renderer';
import Enzyme, { mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
Enzyme.configure({ adapter: new Adapter() });
/* other tests */
test('onClick function is called with passed counter value', () => {
const fn = jest.fn();
const component = mount(
<Button onClick={fn} label="this is test label" />
);
component.find('button').simulate('click');
expect(component.state('counter')).toBe(1);
expect(fn.mock.calls[0][0]).toBe(1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment