Skip to content

Commit bca0669

Browse files
committed
fixed 8 non-running tests
1 parent 69b7512 commit bca0669

8 files changed

+31
-18
lines changed

src/app/__tests__/ActionContainer.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ jest.mock('../components/Actions/RouteDescription', () => () => {
138138
});
139139

140140
const MockSwitchApp = jest.fn();
141-
jest.mock('../components/SwitchApp', () => () => {
141+
jest.mock('../components/Actions/SwitchApp', () => () => {
142142
MockSwitchApp();
143143
return <div>MockSwitchApp</div>;
144144
});
@@ -156,7 +156,8 @@ jest.mock('react-redux', () => ({
156156
// const dispatch = jest.fn();
157157

158158
describe('unit testing for ActionContainer', () => {
159-
const useDispatchMock = useDispatch as jest.Mock; //getting a reference to the mock function you setup during jest.mock configuration on line 18
159+
const useDispatchMock = (useDispatch as unknown) as jest.Mock; // make the test run
160+
// const useDispatchMock = useDispatch as jest.Mock; //getting a reference to the mock function you setup during jest.mock configuration on line 18
160161
const dummyDispatch = jest.fn(); //separate mock function created because we need to explicitly define on line 30 what
161162
useDispatchMock.mockReturnValue(dummyDispatch); //exactly useDispatchMock returns (which is a jest.fn())
162163
beforeEach(() => {

src/app/__tests__/ButtonContainer.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ global.URL.createObjectURL = jest.fn(() => 'https://pdf.com');
142142
global.URL.revokeObjectURL = jest.fn();
143143

144144
describe('Unit testing for ButtonContainer', () => {
145-
const useDispatchMock = useDispatch as jest.Mock; //getting a reference to the mock function you setup during jest.mock configuration on line 18
145+
const useDispatchMock = (useDispatch as unknown) as jest.Mock; // make the test run
146+
// const useDispatchMock = useDispatch as jest.Mock; //getting a reference to the mock function you setup during jest.mock configuration on line 18
146147
const dummyDispatch = jest.fn(); //separate mock function created because we need to explicitly define on line 30 what
147148
useDispatchMock.mockReturnValue(dummyDispatch); //exactly useDispatchMock returns (which is a jest.fn())
148149
beforeEach;

src/app/__tests__/ErrorContainer.test.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ const render = (component) => rtlRender(<Provider store={customStore}>{component
131131
// };
132132

133133
const MockErrorMsg = jest.fn();
134-
jest.mock('../components/ErrorMsg', () => () => {
134+
jest.mock('../components/ErrorHandling/ErrorMsg', () => () => {
135135
MockErrorMsg();
136136
return <div>MockErrorMsg</div>;
137137
});
@@ -142,51 +142,56 @@ jest.mock('../components/ErrorMsg', () => () => {
142142
// const dispatch = jest.fn();
143143
// mockeduseStoreContext.mockImplementation(() => [state, dispatch]);
144144

145+
// added to fix broken tests
146+
const props = {
147+
port: null,
148+
};
149+
145150
describe('unit testing for ErrorContainer.tsx', () => {
146151
test('logo image renders as expected', () => {
147-
render(<ErrorContainer />);
152+
render(<ErrorContainer {...props} />); // added {...props} to fix broken test
148153
expect(screen.getByAltText('Reactime Logo')).toBeInTheDocument();
149154
});
150155

151156
test('ErrorMsg component renders as expected', () => {
152-
render(<ErrorContainer />);
157+
render(<ErrorContainer {...props} />); // added {...props} to fix broken test
153158
expect(screen.getByText('MockErrorMsg')).toBeInTheDocument();
154159
});
155160

156161
test('Reactime website shows as expected', () => {
157-
render(<ErrorContainer />);
162+
render(<ErrorContainer {...props} />); // added {...props} to fix broken test
158163
expect(screen.getByText('Please visit the Reactime Github for more info.')).toBeInTheDocument();
159164
});
160165

161166
describe('Loading Checks show up as expected', () => {
162167
test('Content script launching check shows', () => {
163-
render(<ErrorContainer />);
168+
render(<ErrorContainer {...props} />); // added {...props} to fix broken test
164169
expect(
165170
screen.getByText(`Checking if content script has been launched on current tab`),
166171
).toBeInTheDocument();
167172
});
168173
test('React Dev Tool Install check shows', () => {
169-
render(<ErrorContainer />);
174+
render(<ErrorContainer {...props} />); // added {...props} to fix broken test
170175
expect(
171176
screen.getByText(`Checking if React Dev Tools has been installed`),
172177
).toBeInTheDocument();
173178
});
174179
test('Compatible app check shows', () => {
175-
render(<ErrorContainer />);
180+
render(<ErrorContainer {...props} />); // added {...props} to fix broken test
176181
expect(screen.getByText(`Checking if target is a compatible React app`)).toBeInTheDocument();
177182
});
178183
});
179184

180185
describe('Launching header shows correct tab info', () => {
181186
test('When currentTitle has no target', () => {
182-
render(<ErrorContainer />);
187+
render(<ErrorContainer {...props} />); // added {...props} to fix broken test
183188
expect(screen.getByText(`Launching Reactime on tab: No Target`)).toBeInTheDocument();
184189
expect(screen.queryByText(`Launching Reactime on tab: Test Page`)).not.toBeInTheDocument();
185190
});
186191

187192
test('When currentTitle has a target title', () => {
188193
customInitialState.main.currentTitle = 'Test Page';
189-
render(<ErrorContainer />);
194+
render(<ErrorContainer {...props} />); // added {...props} to fix broken test
190195
expect(screen.getByText(`Launching Reactime on tab: Test Page`)).toBeInTheDocument();
191196
expect(screen.queryByText(`Launching Reactime on tab: No Target`)).not.toBeInTheDocument();
192197
});

src/app/__tests__/MainSlider.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const render = (component) => rtlRender(<Provider store={customStore}>{component
3737
describe('Unit testing for MainSlider.jsx', () => {
3838
const props = {
3939
snapshotsLength: 1,
40+
className: 'String' // added to fix the test
4041
};
4142

4243
describe('When user only has one snapshot to view', () => {
@@ -51,6 +52,7 @@ describe('Unit testing for MainSlider.jsx', () => {
5152
describe('When there are multiple snapshots and we are looking in between', () => {
5253
const props = {
5354
snapshotsLength: 3,
55+
className: 'String' // added to fix the test
5456
};
5557

5658
test('Component should have min, max, value with correct values to indicate slider position when there are multiple snapshots', () => {

src/app/__tests__/TravelContainer.test.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ const renderWithTheme = (component) => {
135135
};
136136

137137
const mockSlider = jest.fn();
138-
jest.mock('../components/MainSlider', () => (props) => {
138+
jest.mock('../components/TimeTravel/MainSlider', () => (props) => {
139139
mockSlider(props);
140140
return <div>MockSlider</div>;
141141
});
142142

143143
const mockDropDown = jest.fn();
144-
jest.mock('../components/Dropdown', () => (props) => {
144+
jest.mock('../components/TimeTravel/Dropdown', () => (props) => {
145145
mockDropDown(props);
146146
return <div>mockDropDown</div>;
147147
});
@@ -182,7 +182,8 @@ describe('All elements appear in the TravelContainer module', () => {
182182
});
183183

184184
describe('Testing play/pause button', () => {
185-
const useDispatchMock = useDispatch as jest.Mock; //getting a reference to the mock function you setup during jest.mock configuration on line 154
185+
const useDispatchMock = (useDispatch as unknown) as jest.Mock; // make the test run
186+
// const useDispatchMock = useDispatch as jest.Mock; //getting a reference to the mock function you setup during jest.mock configuration on line 154
186187
const dummyDispatch = jest.fn();
187188
useDispatchMock.mockReturnValue(dummyDispatch);
188189
beforeEach(() => {

src/app/__tests__/TravelForwardBackward.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ jest.mock('react-redux', () => ({
136136
//needed to isolate the testing of the forward and backward buttons as behavior was affected when within the travelContainer file
137137

138138
describe('Testing backward and forward button', () => {
139-
const useDispatchMock = useDispatch as jest.Mock; //getting a reference to the mock function you setup during jest.mock configuration on line 154
139+
const useDispatchMock = (useDispatch as unknown) as jest.Mock; // make the test run
140+
// const useDispatchMock = useDispatch as jest.Mock; //getting a reference to the mock function you setup during jest.mock configuration on line 154
140141
const dummyDispatch = jest.fn();
141142
useDispatchMock.mockReturnValue(dummyDispatch);
142143
beforeEach(() => {

src/app/__tests__/WebMetrics.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ jest.mock('react-redux', () => ({
1010
...jest.requireActual('react-redux'), // Use the actual react-redux module except for the functions you want to mock
1111
useDispatch: jest.fn(), // set up a mock function for useDispatch
1212
}));
13-
const useDispatchMock = useDispatch as jest.Mock; //getting a reference to the mock function you setup during jest.mock configuration on line 18
13+
const useDispatchMock = (useDispatch as unknown) as jest.Mock; // make the test run
14+
// const useDispatchMock = useDispatch as jest.Mock; //getting a reference to the mock function you setup during jest.mock configuration on line 18
1415
const dummyDispatch = jest.fn(); //separate mock function created because we need to explicitly define on line 30 what
1516
useDispatchMock.mockReturnValue(dummyDispatch); //exactly useDispatchMock returns (which is a jest.fn())
1617
const customTabs = {

src/app/__tests__/action.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ jest.mock('react-redux', () => ({
2222
const render = (component) => rtlRender(<Provider store={store}>{component}</Provider>);
2323

2424
describe('Unit testing for Action.tsx', () => {
25-
const useDispatchMock = useDispatch as jest.Mock; //getting a reference to the mock function you setup during jest.mock configuration on line 18
25+
const useDispatchMock = (useDispatch as unknown) as jest.Mock; // attempt to make the test run
26+
// const useDispatchMock = useDispatch as jest.Mock; //getting a reference to the mock function you setup during jest.mock configuration on line 18
2627
const dummyDispatch = jest.fn(); //separate mock function created because we need to explicitly define on line 30 what
2728
useDispatchMock.mockReturnValue(dummyDispatch); //exactly useDispatchMock returns (which is a jest.fn())
2829
const props = {

0 commit comments

Comments
 (0)