Skip to content

Instantly share code, notes, and snippets.

@pechitook
Last active August 1, 2016 03:17
Show Gist options
  • Save pechitook/361972dafd1eae25ea8273a674e084ff to your computer and use it in GitHub Desktop.
Save pechitook/361972dafd1eae25ea8273a674e084ff to your computer and use it in GitHub Desktop.
import React from 'react';
import { shallow, mount } from 'enzyme';
import Checkbox from 'components/Form/Checkbox';
import expect from 'expect';
import 'jsdom-global/register';
describe('<Checkbox />', () => {
it('adds checked attribute to input', () => {
const wrapper = shallow(<Checkbox checked />);
const input = wrapper.find('input');
expect(input.props().defaultChecked).toBe(true);
});
it('adds disabled attribute to input', () => {
const wrapper = shallow(<Checkbox disabled />);
const input = wrapper.find('input');
expect(input.props().disabled).toBe(true);
});
it('calls the onChange function', () => {
const onChange = expect.createSpy();
const wrapper = mount(<Checkbox onChange={onChange} />);
const input = wrapper.find('input');
input.simulate('change');
expect(onChange).toHaveBeenCalled();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment