Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Romain Gaillard
Added: Oct 5, 2021 3:35 PM
Modified: Oct 5, 2021 3:39 PM
Views: 273
Tags: hook hooks tu
  1. import { Provider } from 'react-redux';
  2. import { renderHook } from '@testing-library/react-hooks';
  3. import React from 'react';
  4.  
  5. import useFreeShipping from '../useFreeShipping';
  6.  
  7. jest.unmock('react-redux');
  8.  
  9. const mockStore = {
  10.   getState: () => ({}),
  11.   subscribe: Function.prototype,
  12.   dispatch: Function.prototype,
  13. };
  14.  
  15. describe('useFreeShipping', () => {
  16.   test('with freeShipping', () => {
  17.     const wrapper = ({ children }) => <Provider store={mockStore}>{children}</Provider>;
  18.     const freeShippingMessage = 'Livraison gratuite';
  19.     const { result } = renderHook(() => useFreeShipping(freeShippingMessage), { wrapper });
  20.     expect(result.current).toEqual({
  21.       hasFreeShippingTooltip: true,
  22.       exponentMinimalBuy: null,
  23.       freeShippingLabel: 'Livraison gratuite',
  24.       freeShippingMinimalBuy: '',
  25.       hasModalDisplayed: false,
  26.       onClick: expect.any(Function),
  27.       onClose: expect.any(Function),
  28.     });
  29.   });
  30.  
  31.   test('with open modal freeShipping', () => {
  32.     const freeShippingMessage = 'Livraison gratuite';
  33.     const { result } = renderHook(() => useFreeShipping(freeShippingMessage));
  34.     expect(result.current.hasModalDisplayed).toEqual(false);
  35.     result.current.onClick();
  36.     expect(result.current.hasModalDisplayed).toEqual(true);
  37.   });
  38. });
  39.