UNPKG

@shopgate/pwa-common

Version:

Common library for the Shopgate Connect PWA.

60 lines 1.64 kB
import React from 'react'; import { shallow, mount } from 'enzyme'; import { Disconnected as Link } from "./index"; import { jsx as _jsx } from "react/jsx-runtime"; describe('<Link />', () => { const historyPush = jest.fn(); const historyReplace = jest.fn(); const pathname = '/'; const state = { x: 5 }; beforeEach(() => { jest.useFakeTimers(); jest.clearAllMocks(); }); afterEach(() => { jest.useRealTimers(); }); it('renders with children', () => { const wrapper = shallow(/*#__PURE__*/_jsx(Link, { href: pathname, historyPush: historyPush, historyReplace: historyReplace, children: /*#__PURE__*/_jsx("span", {}) })); expect(wrapper).toMatchSnapshot(); expect(wrapper.find('span').length).toBe(1); }); it('handles a push', () => { const wrapper = mount(/*#__PURE__*/_jsx(Link, { href: pathname, state: state, historyPush: historyPush, historyReplace: historyReplace, children: /*#__PURE__*/_jsx("span", {}) })); wrapper.find('div').simulate('click'); jest.runAllTimers(); expect(historyPush).toHaveBeenLastCalledWith({ pathname, state }); }); it('handles a replace', () => { const wrapper = mount(/*#__PURE__*/_jsx(Link, { href: pathname, historyPush: historyPush, historyReplace: historyReplace, state: state, replace: true, children: /*#__PURE__*/_jsx("span", {}) })); wrapper.find('div').simulate('click'); jest.runAllTimers(); expect(historyReplace).toHaveBeenLastCalledWith({ pathname, state }); }); });