UNPKG

react-spatial

Version:

Components to build React map apps.

70 lines (60 loc) 2.02 kB
import React from 'react'; import { configure, shallow } from 'enzyme'; import Adapter from 'enzyme-adapter-react-16'; import renderer from 'react-test-renderer'; import ActionLink from './ActionLink'; configure({ adapter: new Adapter() }); describe('ActionLink', function () { describe('when no properties are set', function () { var spy = null; beforeEach(function () { window.console.error = jest.fn().mockImplementation(function () {}); spy = jest.spyOn(window.console, 'error'); }); afterEach(function () { spy.mockRestore(); window.console.error.mockRestore(); }); test('displays 2 errors in the console', function () { shallow(React.createElement( ActionLink, null )); expect(spy).toHaveBeenCalledTimes(2); }); test('matches snapshot', function () { var component = renderer.create(React.createElement( ActionLink, null )); var tree = component.toJSON(); expect(tree).toMatchSnapshot(); }); }); describe('when properties are set', function () { var label = 'foo'; var title = ['bar']; var className = ['qux']; var onClick = function () {}; test('matches snapshot', function () { var component = renderer.create( React.createElement( ActionLink, { title: title, className: className, onClick: onClick }, label ) ); var tree = component.toJSON(); expect(tree).toMatchSnapshot(); }); test('executes onClick property function', function () { var fn = jest.fn(onClick); var fn2 = jest.fn(); var evt = { preventDefault: fn2, stopPropagation: fn2, }; var wrapper = shallow( React.createElement( ActionLink, { title: title, className: className, onClick: fn }, label ) ); wrapper.simulate('click', evt); expect(fn2).toHaveBeenCalledTimes(2); expect(fn.mock.calls[0][0]).toBe(evt); }); }); }); //# sourceMappingURL=ActionLink.test.js.map