Skip to content

Commit 7cdba78

Browse files
committed
Upgrade testing-library dependencies
1 parent 7ade5a5 commit 7cdba78

File tree

6 files changed

+94
-109
lines changed

6 files changed

+94
-109
lines changed

website/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@
3838
"@packtracker/webpack-plugin": "2.3.0",
3939
"@pmmmwh/react-refresh-webpack-plugin": "0.5.15",
4040
"@svgr/webpack": "8.1.0",
41-
"@testing-library/jest-dom": "5.17.0",
42-
"@testing-library/react": "11.2.7",
43-
"@testing-library/user-event": "12.8.3",
41+
"@testing-library/dom": "10.4.0",
42+
"@testing-library/jest-dom": "6.6.3",
43+
"@testing-library/react": "16.0.1",
44+
"@testing-library/user-event": "14.5.2",
4445
"@types/body-scroll-lock": "2.6.2",
4546
"@types/enzyme": "3.10.18",
4647
"@types/jest": "29.5.14",

website/src/test-utils/renderWithRouterMatch.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { render } from '@testing-library/react';
2+
import type { RenderOptions } from '@testing-library/react';
23
import type { ReactNode } from 'react';
34
import { Route, Router } from 'react-router-dom';
45
import createHistory from './createHistory';
@@ -18,12 +19,14 @@ export default function renderWithRouterMatch(
1819
path?: string;
1920
location?: Parameters<typeof createHistory>[0];
2021
},
22+
renderOptions?: Omit<RenderOptions, 'queries'> | undefined,
2123
) {
2224
const { history } = createHistory(location);
2325
const view = render(
2426
<Router history={history}>
2527
<Route path={path}>{children}</Route>
2628
</Router>,
29+
renderOptions,
2730
);
2831
return {
2932
history,

website/src/views/errors/ModuleFinderApiError.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe(ModuleFinderApiError, () => {
4646
push: jest.fn(),
4747
};
4848
const tryAgainButton = getByRole('button');
49-
userEvent.click(tryAgainButton);
49+
await userEvent.click(tryAgainButton);
5050
expect(searchkit.history.push).toHaveBeenCalled();
5151
expect(history.location.pathname).toBe('/modules');
5252
expect(history.location.search).toBe('?q=GER1000&sem[0]=1&sem[1]=2&sem[2]=3&sem[3]=4');

website/src/views/layout/GlobalSearchContainer.test.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,22 @@ describe('GlobalSearchContainer', () => {
8181
expect(mockedFetchVenueList).toHaveBeenCalled();
8282
});
8383

84-
test('shows no choices when search is too short', () => {
84+
test('shows no choices when search is too short', async () => {
8585
const { getByRole, queryAllByRole } = make();
8686

8787
// Expect not to show choices when search string is too short
88-
userEvent.type(getByRole('textbox'), '1');
88+
await userEvent.type(getByRole('textbox'), '1');
8989
expect(queryAllByRole('option')).toHaveLength(0);
9090

9191
// Expect to show choices when search string is long enough
92-
userEvent.type(getByRole('textbox'), '1');
92+
await userEvent.type(getByRole('textbox'), '1');
9393
expect(queryAllByRole('option')).not.toHaveLength(0);
9494
});
9595

96-
test('shows at most 10 choices when there are many venues and modules', () => {
96+
test('shows at most 10 choices when there are many venues and modules', async () => {
9797
const { getByRole, getAllByRole } = make();
9898
// Space is intentional - min chars needed to trigger search is 2, so you need an additional character.
99-
userEvent.type(getByRole('textbox'), '1 ');
99+
await userEvent.type(getByRole('textbox'), '1 ');
100100
expect(getAllByRole('option').map((elem) => elem.textContent)).toMatchInlineSnapshot(`
101101
[
102102
"View All Courses",
@@ -115,11 +115,11 @@ describe('GlobalSearchContainer', () => {
115115
`);
116116
});
117117

118-
test('prioritize showing venues when there are many venues even if there are modules', () => {
118+
test('prioritize showing venues when there are many venues even if there are modules', async () => {
119119
const { getByRole, getAllByRole } = make({
120120
moduleBank: { moduleList: MODULES.slice(0, 5) },
121121
});
122-
userEvent.type(getByRole('textbox'), '1 ');
122+
await userEvent.type(getByRole('textbox'), '1 ');
123123
expect(getAllByRole('option').map((elem) => elem.textContent)).toMatchInlineSnapshot(`
124124
[
125125
"View All Venues",
@@ -153,11 +153,11 @@ describe('GlobalSearchContainer', () => {
153153
`);
154154
});
155155

156-
test('shows at most 10 choices when there are many modules', () => {
156+
test('shows at most 10 choices when there are many modules', async () => {
157157
const { getByRole, getAllByRole } = make({
158158
venueBank: { venueList: VENUES.slice(0, 2) },
159159
});
160-
userEvent.type(getByRole('textbox'), '1 ');
160+
await userEvent.type(getByRole('textbox'), '1 ');
161161
expect(getAllByRole('option').map((elem) => elem.textContent)).toMatchInlineSnapshot(`
162162
[
163163
"View All Courses",
@@ -176,9 +176,9 @@ describe('GlobalSearchContainer', () => {
176176
`);
177177
});
178178

179-
test('shows all results when there are few', () => {
179+
test('shows all results when there are few', async () => {
180180
const { getByRole, getAllByRole } = make();
181-
userEvent.type(getByRole('textbox'), 'AA');
181+
await userEvent.type(getByRole('textbox'), 'AA');
182182
expect(getAllByRole('option').map((elem) => elem.textContent)).toMatchInlineSnapshot(`
183183
[
184184
"View All Courses",
@@ -189,12 +189,12 @@ describe('GlobalSearchContainer', () => {
189189
`);
190190
});
191191

192-
test('show many results if the search only returns modules', () => {
192+
test('show many results if the search only returns modules', async () => {
193193
const { getByRole, getAllByRole } = make({
194194
venueBank: { venueList: range(100).map((n) => `Venue ${n}`) },
195195
});
196196

197-
userEvent.type(getByRole('textbox'), '1010');
197+
await userEvent.type(getByRole('textbox'), '1010');
198198
expect(getAllByRole('option').map((elem) => elem.textContent)).toMatchInlineSnapshot(`
199199
[
200200
"View All Courses",
@@ -272,12 +272,12 @@ describe('GlobalSearchContainer', () => {
272272
`);
273273
});
274274

275-
test('show many results if the search only returns venues', () => {
275+
test('show many results if the search only returns venues', async () => {
276276
const { getByRole, getAllByRole } = make({
277277
venueBank: { venueList: range(100).map((n) => `Venue ${n}`) },
278278
});
279279

280-
userEvent.type(getByRole('textbox'), 'venue');
280+
await userEvent.type(getByRole('textbox'), 'venue');
281281
expect(getAllByRole('option').map((elem) => elem.textContent)).toMatchInlineSnapshot(`
282282
[
283283
"View All Venues",

website/src/views/timetable/TimetableContainer.test.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { screen, waitFor } from '@testing-library/react';
2+
import type { RenderOptions } from '@testing-library/react';
23
import { Provider } from 'react-redux';
34
import axios, { AxiosHeaders, AxiosResponse } from 'axios';
45
import { produce } from 'immer';
@@ -48,11 +49,17 @@ const relevantStoreContents = {
4849

4950
const initialState = reducers(undefined, initAction());
5051

51-
function make(location: string, storeOverrides: Partial<typeof relevantStoreContents> = {}) {
52+
function make(
53+
location: string,
54+
options: {
55+
storeOverrides?: Partial<typeof relevantStoreContents>;
56+
renderOptions?: Omit<RenderOptions, 'queries'> | undefined;
57+
} = {},
58+
) {
5259
const { store } = configureStore(
5360
produce(initialState, (draft) => {
5461
draft.app.activeSemester =
55-
storeOverrides.app?.activeSemester ?? relevantStoreContents.app.activeSemester;
62+
options.storeOverrides?.app?.activeSemester ?? relevantStoreContents.app.activeSemester;
5663
}),
5764
);
5865

@@ -69,6 +76,7 @@ function make(location: string, storeOverrides: Partial<typeof relevantStoreCont
6976
path: '/timetable/:semester?/:action?',
7077
location,
7178
},
79+
options.renderOptions,
7280
),
7381
};
7482
}
@@ -94,7 +102,9 @@ describe(TimetableContainerComponent, () => {
94102
// Use for-of loop as we `waitFor` must be executed sequentially.
95103
// eslint-disable-next-line no-restricted-syntax
96104
for (const semester of semesters) {
97-
const { history } = make('/timetable', { app: { activeSemester: semester } });
105+
const { history } = make('/timetable', {
106+
storeOverrides: { app: { activeSemester: semester } },
107+
});
98108
// eslint-disable-next-line no-await-in-loop
99109
await waitFor(() => expect(history.location.pathname).toBe(timetablePage(semester)));
100110
}
@@ -176,10 +186,11 @@ describe(TimetableContainerComponent, () => {
176186
expect(screen.getByRole('button', { name: 'Import' })).toBeInTheDocument();
177187
});
178188

179-
test('should display saved timetable when there is no imported timetable', () => {
189+
test('should display saved timetable when there is no imported timetable', async () => {
180190
const semester = 1;
181191
const location = timetablePage(semester);
182-
const { store } = make(location);
192+
// TODO: Get this test to work with the new createRoot API, i.e. legacyRoot = false.
193+
const { store } = make(location, { renderOptions: { legacyRoot: true } });
183194

184195
// Populate moduleBank using "succeeded" requests-middleware requests
185196
store.dispatch({ type: SUCCESS_KEY(FETCH_MODULE), payload: CS1010S });

0 commit comments

Comments
 (0)