Skip to content

Commit eee5d5f

Browse files
committed
timetable/test: Render with createRoot
1 parent 7cdba78 commit eee5d5f

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { screen, waitFor } from '@testing-library/react';
1+
import { act, screen, waitFor } from '@testing-library/react';
22
import type { RenderOptions } from '@testing-library/react';
33
import { Provider } from 'react-redux';
44
import axios, { AxiosHeaders, AxiosResponse } from 'axios';
@@ -189,16 +189,19 @@ describe(TimetableContainerComponent, () => {
189189
test('should display saved timetable when there is no imported timetable', async () => {
190190
const semester = 1;
191191
const location = timetablePage(semester);
192-
// TODO: Get this test to work with the new createRoot API, i.e. legacyRoot = false.
193-
const { store } = make(location, { renderOptions: { legacyRoot: true } });
192+
const { store } = make(location);
194193

195194
// Populate moduleBank using "succeeded" requests-middleware requests
196-
store.dispatch({ type: SUCCESS_KEY(FETCH_MODULE), payload: CS1010S });
197-
store.dispatch({ type: SUCCESS_KEY(FETCH_MODULE), payload: CS3216 });
195+
await act(async () => {
196+
store.dispatch({ type: SUCCESS_KEY(FETCH_MODULE), payload: CS1010S });
197+
store.dispatch({ type: SUCCESS_KEY(FETCH_MODULE), payload: CS3216 });
198+
});
198199

199200
// Populate mock timetable
200-
const timetable = { CS1010S: { Lecture: '1' }, CS3216: { Lecture: '1' } };
201-
(store.dispatch as Dispatch)(setTimetable(semester, timetable));
201+
await act(async () => {
202+
const timetable = { CS1010S: { Lecture: '1' }, CS3216: { Lecture: '1' } };
203+
(store.dispatch as Dispatch)(setTimetable(semester, timetable));
204+
});
202205

203206
// Expect nothing to be fetched as timetable exists in `moduleBank`.
204207
expect(screen.queryByText(/Loading/)).not.toBeInTheDocument();

0 commit comments

Comments
 (0)