Fix broken StudioHome tests (#2291)

There were a ton of problems with these tests, but the main one was the use of `waitFor` without `await`, causing all of the code inside each `waitFor` block to essentially be ignored.

Other problems fixed:
* Rendering a router inside a router was causing most of the render() calls to fail (our custom `render()` already provides a router so there's no need to provide one in the test case)
* Use of `testid` instead of queries based on what users see
* Tests could match on content in the body when trying to make assertions about the header
* Mock imported via `index.js` was causing `jest-haste-map` to print warnings about duplicate mock names (this is still happening for other mocks)
* Passing `courses: null` instead of `courses: []` was causing a broken render on two of the tests.

I also made other cleanups to follow best practices.
This commit is contained in:
Braden MacDonald
2025-07-17 13:45:22 -07:00
committed by GitHub
parent 2db6d89fca
commit bd18e874b5
21 changed files with 271 additions and 325 deletions

View File

@@ -14,7 +14,7 @@ import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
import { AppProvider } from '@edx/frontend-platform/react';
import MockAdapter from 'axios-mock-adapter';
import { studioHomeMock } from '../../studio-home/__mocks__';
import studioHomeMock from '@src/studio-home/__mocks__/studioHomeMock';
import { getStudioHomeApiUrl } from '../../studio-home/data/api';
import { fetchStudioHomeData } from '../../studio-home/data/thunks';
import { RequestStatus } from '../../data/constants';

View File

@@ -1,5 +1,5 @@
import { RequestStatus } from '../../../data/constants';
import { studioHomeMock } from '../../../studio-home/__mocks__';
import { RequestStatus } from '@src/data/constants';
import studioHomeMock from '@src/studio-home/__mocks__/studioHomeMock';
export const courseId = 'course-v1:edX+DemoX+Demo_Course';