Skip to content

Commit 2ededa1

Browse files
committed
MainContainer Test is fixed
1 parent 545b749 commit 2ededa1

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

src/app/__tests__/MainContainer.test.tsx

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,23 @@
22
import React from 'react';
33
import { render, screen } from '@testing-library/react';
44
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
622

723
const chrome = require('sinon-chrome');
824

@@ -36,15 +52,12 @@ jest.mock('../containers/ErrorContainer', () => (props) => {
3652
return <div>mockErrorContainer</div>;
3753
});
3854

39-
const state = {
40-
tabs: {},
41-
currentTab: null,
42-
};
4355
const dispatch = jest.fn();
56+
4457
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));
4861

4962
global.chrome = chrome;
5063
const port = {
@@ -90,12 +103,11 @@ describe('With no snapshots, should not render any containers', () => {
90103
describe('With snapshots, should render all containers', () => {
91104
beforeEach(() => {
92105
render(<MainContainer />);
93-
mockedUseStoreContext.mockClear();
94106
dispatch.mockClear();
95107
mockErrorContainer.mockClear();
96108
// @ts-ignore
97-
state.currentTab = 87;
98-
state.tabs[87] = {
109+
mockState.main.currentTab = 87;
110+
mockState.main.tabs[87] = {
99111
snapshots: [{}],
100112
status: {
101113
contentScriptLaunched: true,

0 commit comments

Comments
 (0)