@shopgate/pwa-common
Version:
Common library for the Shopgate Connect PWA.
1 lines • 1.28 kB
JavaScript
import React from'react';import{shallow,mount}from'enzyme';import{Disconnected as Link}from"./index";describe('<Link />',function(){var historyPush=jest.fn();var historyReplace=jest.fn();var pathname='/';var state={x:5};beforeEach(function(){jest.useFakeTimers();jest.clearAllMocks();});afterEach(function(){jest.useRealTimers();});it('renders with children',function(){var wrapper=shallow(React.createElement(Link,{href:pathname,historyPush:historyPush,historyReplace:historyReplace},React.createElement("span",null)));expect(wrapper).toMatchSnapshot();expect(wrapper.find('span').length).toBe(1);});it('handles a push',function(){var wrapper=mount(React.createElement(Link,{href:pathname,state:state,historyPush:historyPush,historyReplace:historyReplace},React.createElement("span",null)));wrapper.find('div').simulate('click');jest.runAllTimers();expect(historyPush).toHaveBeenLastCalledWith({pathname:pathname,state:state});});it('handles a replace',function(){var wrapper=mount(React.createElement(Link,{href:pathname,historyPush:historyPush,historyReplace:historyReplace,state:state,replace:true},React.createElement("span",null)));wrapper.find('div').simulate('click');jest.runAllTimers();expect(historyReplace).toHaveBeenLastCalledWith({pathname:pathname,state:state});});});