Skip to content

Commit 99ed25c

Browse files
committed
updated tests to reflect the ts files
1 parent 730fe74 commit 99ed25c

File tree

7 files changed

+22
-20
lines changed

7 files changed

+22
-20
lines changed

src/app/__tests__/ActionContainer.test.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,11 @@ const state = {
106106
};
107107

108108
const dispatch = jest.fn();
109-
const resetSlider = jest.fn();
110109
jest.spyOn(React, 'useEffect').mockImplementation(() => jest.fn());
111110
jest.mock('../store');
112-
useStoreContext.mockImplementation(() => [state, dispatch]);
111+
112+
const mockeduseStoreContext = jest.mocked(useStoreContext);
113+
mockeduseStoreContext.mockImplementation(() => [state, dispatch]);
113114

114115
const MockRouteDescription = jest.fn();
115116
jest.mock('../components/RouteDescription', () => () => {
@@ -125,7 +126,7 @@ jest.mock('../components/SwitchApp', () => () => {
125126

126127
describe('unit testing for ActionContainer', () => {
127128
beforeEach(() => {
128-
useStoreContext.mockClear();
129+
mockeduseStoreContext.mockClear();
129130
dispatch.mockClear();
130131
render(<ActionContainer actionView={true} />);
131132
});

src/app/__tests__/ButtonContainer.test.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
22
import { render, screen, fireEvent } from '@testing-library/react';
3-
import userEvent from '@testing-library/user-event';
43
import '@testing-library/jest-dom/extend-expect'; // needed this to extend the jest-dom assertions (ex toHaveTextContent)
54
import { TextEncoder } from 'util';
65
global.TextEncoder = TextEncoder;
@@ -9,18 +8,12 @@ import { useStoreContext } from '../store';
98

109
// const { Steps } = require('intro.js-react');
1110
jest.mock('../store');
11+
const mockedUsedStoreContext = jest.mocked(useStoreContext);
12+
// useStoreContext as jest.Mock<useStoreContext>.mockImplementaton(() => [state, dispatch])
1213

1314
global.URL.createObjectURL = jest.fn(() => 'https://pdf.com');
1415
global.URL.revokeObjectURL = jest.fn();
1516

16-
const fileDownload = {
17-
href: jest.fn(),
18-
};
19-
20-
const URL = { revokeObjectURL: jest.fn() };
21-
// @ts-ignore
22-
// jest.spyOn(document, 'createElement').mockImplementation(() => fileDownload);
23-
2417
describe('Unit testing for ButtonContainer', () => {
2518
beforeEach;
2619

@@ -46,11 +39,12 @@ describe('Unit testing for ButtonContainer', () => {
4639
const importHandler = jest.fn();
4740
const fileDownload = jest.fn();
4841

49-
useStoreContext.mockImplementation(() => [state, dispatch]);
42+
mockedUsedStoreContext.mockImplementation(() => [state, dispatch]);
43+
// useStoreContext.mockImplementation(() => [state, dispatch]);
5044

5145
beforeEach(() => {
5246
dispatch.mockClear();
53-
useStoreContext.mockClear();
47+
mockedUsedStoreContext.mockClear();
5448
currentTab.mode = {
5549
paused: false,
5650
persist: false,

src/app/__tests__/ErrorContainer.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ jest.mock('../components/ErrorMsg', () => () => {
1717
});
1818

1919
jest.mock('../store');
20+
const mockeduseStoreContext = jest.mocked(useStoreContext);
21+
2022
const dispatch = jest.fn();
21-
useStoreContext.mockImplementation(() => [state, dispatch]);
23+
mockeduseStoreContext.mockImplementation(() => [state, dispatch]);
2224

2325
describe('unit testing for ErrorContainer.tsx', () => {
2426
test('logo image renders as expected', () => {

src/app/__tests__/MainContainer.test.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//@ts-nocheck
12
import React from 'react';
23
import { render, screen } from '@testing-library/react';
34
import MainContainer from '../containers/MainContainer';
@@ -40,7 +41,8 @@ const state = {
4041
const dispatch = jest.fn();
4142
jest.mock('../../../node_modules/intro.js/introjs.css', () => jest.fn());
4243
jest.mock('../store');
43-
useStoreContext.mockImplementation(() => [state, dispatch]);
44+
const mockedUseStoreContext = jest.mocked(useStoreContext);
45+
mockedUseStoreContext.mockImplementation(() => [state, dispatch]);
4446

4547
global.chrome = chrome;
4648
const port = {
@@ -86,9 +88,10 @@ describe('With no snapshots, should not render any containers', () => {
8688
describe('With snapshots, should render all containers', () => {
8789
beforeEach(() => {
8890
render(<MainContainer />);
89-
useStoreContext.mockClear();
91+
mockedUseStoreContext.mockClear();
9092
dispatch.mockClear();
9193
mockErrorContainer.mockClear();
94+
// @ts-ignore
9295
state.currentTab = 87;
9396
state.tabs[87] = {
9497
snapshots: [{}],

src/app/__tests__/MainSlider.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import MainSlider from '../components/MainSlider';
77
import { useStoreContext } from '../store';
88

99
jest.mock('../store');
10+
const mockeduseStoreContext = jest.mocked(useStoreContext);
1011

1112
describe('Unit testing for MainSlider.jsx', () => {
1213
const props = {
@@ -23,7 +24,7 @@ describe('Unit testing for MainSlider.jsx', () => {
2324
};
2425

2526
const dispatch = jest.fn();
26-
useStoreContext.mockImplementation(() => [state, dispatch]);
27+
mockeduseStoreContext.mockImplementation(() => [state, dispatch]);
2728

2829
describe('When user only has one snapshot to view', () => {
2930
test('Component should have min, max, value with correct values to indicate slider position for correct tab', () => {

src/app/__tests__/TravelContainer.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ const state = {
1717

1818
const play = jest.fn();
1919
const dispatch = jest.fn();
20-
useStoreContext.mockImplementation(() => [state, dispatch]);
2120

2221
jest.mock('../store');
22+
const mockedStoreContext = jest.mocked(useStoreContext);
23+
mockedStoreContext.mockImplementation(() => [state, dispatch]);
2324

2425
const mockSlider = jest.fn();
2526
jest.mock('../components/MainSlider', () => (props) => {

src/app/__tests__/Tutorial.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Tutorial from '../components/Tutorial';
99

1010
const dispatch = jest.fn();
1111
const props = {
12-
currentTabInApp: undefined,
12+
currentTabInApp: 'map',
1313
dispatch,
1414
};
1515

0 commit comments

Comments
 (0)