|
2 | 2 | import React from 'react'; |
3 | 3 | import { render, screen } from '@testing-library/react'; |
4 | 4 | import MainContainer from '../containers/MainContainer'; |
5 | | -import { useStoreContext } from '../store'; |
| 5 | + |
| 6 | +//Added : |
| 7 | +import { useDispatch, useSelector } from 'react-redux'; |
| 8 | + |
| 9 | +jest.mock('react-redux', () => ({ |
| 10 | + useDispatch: jest.fn(), |
| 11 | + useSelector: jest.fn(), |
| 12 | +})); |
| 13 | + |
| 14 | +const mockState = { |
| 15 | + main: { |
| 16 | + tabs: {}, |
| 17 | + currentTab: null, |
| 18 | + }, |
| 19 | +}; |
| 20 | + |
| 21 | +// End |
6 | 22 |
|
7 | 23 | const chrome = require('sinon-chrome'); |
8 | 24 |
|
@@ -36,15 +52,12 @@ jest.mock('../containers/ErrorContainer', () => (props) => { |
36 | 52 | return <div>mockErrorContainer</div>; |
37 | 53 | }); |
38 | 54 |
|
39 | | -const state = { |
40 | | - tabs: {}, |
41 | | - currentTab: null, |
42 | | -}; |
43 | 55 | const dispatch = jest.fn(); |
| 56 | + |
44 | 57 | jest.mock('../../../node_modules/intro.js/introjs.css', () => jest.fn()); |
45 | | -jest.mock('../store'); |
46 | | -const mockedUseStoreContext = jest.mocked(useStoreContext); |
47 | | -mockedUseStoreContext.mockImplementation(() => [state, dispatch]); |
| 58 | + |
| 59 | +useDispatch.mockReturnValue(dispatch); |
| 60 | +useSelector.mockImplementation(callback => callback(mockState)); |
48 | 61 |
|
49 | 62 | global.chrome = chrome; |
50 | 63 | const port = { |
@@ -90,12 +103,11 @@ describe('With no snapshots, should not render any containers', () => { |
90 | 103 | describe('With snapshots, should render all containers', () => { |
91 | 104 | beforeEach(() => { |
92 | 105 | render(<MainContainer />); |
93 | | - mockedUseStoreContext.mockClear(); |
94 | 106 | dispatch.mockClear(); |
95 | 107 | mockErrorContainer.mockClear(); |
96 | 108 | // @ts-ignore |
97 | | - state.currentTab = 87; |
98 | | - state.tabs[87] = { |
| 109 | + mockState.main.currentTab = 87; |
| 110 | + mockState.main.tabs[87] = { |
99 | 111 | snapshots: [{}], |
100 | 112 | status: { |
101 | 113 | contentScriptLaunched: true, |
|
0 commit comments