UNPKG

react-spatial

Version:

Components to build React map apps.

85 lines (72 loc) 2.5 kB
import React from 'react'; import renderer from 'react-test-renderer'; import { configure, shallow } from 'enzyme'; import Adapter from 'enzyme-adapter-react-16'; import Checkbox from './Checkbox'; configure({ adapter: new Adapter() }); describe('Checkbox', function () { describe('matches snapshots', function () { test('for inputType Checkbox.', function () { var component = renderer.create( React.createElement( Checkbox, { className: "tm-checkbox-chbx-example", onClick: function () {} }) ); var tree = component.toJSON(); expect(tree).toMatchSnapshot(); }); test('for inputType Radio.', function () { var checked = true; var component = renderer.create( React.createElement( Checkbox, { className: "tm-checkbox-radio-ex", inputType: "radio", checked: checked, onClick: function () {} }) ); var tree = component.toJSON(); expect(tree).toMatchSnapshot(); }); }); describe('triggers onClick', function () { var wrapper; var spy; var checked = true; var funcs = { onCheckboxClick: function () {}, onCheckboxChange: function () {}, }; var expectCalled = function () { expect(spy).toHaveBeenCalledTimes(1); }; beforeEach(function () { wrapper = shallow( React.createElement( Checkbox, { className: "tm-checkbox-ex", checked: checked, onClick: function () { return funcs.onCheckboxClick(); }, onChange: function () { return funcs.onCheckboxChange(); } }) ); spy = jest.spyOn(funcs, 'onCheckboxClick'); }); afterEach(function () { spy.mockRestore(); }); test('Checkbox should be clicked.', function () { wrapper.find({ type: 'checkbox' }).simulate('click'); expectCalled(); }); test('Checkbox should not be clicked.', function () { wrapper .find('label') .first() .simulate('keypress', { which: 10 }); expect(spy).toHaveBeenCalledTimes(0); }); test('Checkbox should be clicked.', function () { wrapper .find('label') .first() .simulate('keypress', { which: 13 }); expectCalled(); }); test('Checkbox input should change.', function () { var spyChange = jest.spyOn(funcs, 'onCheckboxChange'); wrapper.find({ type: 'checkbox' }).simulate('change'); expect(spyChange).toHaveBeenCalledTimes(1); }); }); }); //# sourceMappingURL=Checkbox.test.js.map