openedx / openedx/frontend-app-authoring

Improve brittle tests related to axios mocks

Open
#2,723 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

code health good first issue help wanted
Dominant language
TypeScript
Stars
17
Forks
218
Avg merge
9d 20h
Merged PRs (30d)
20

Description

While writing tests for https://github.com/openedx/frontend-app-authoring/pull/2685, which adds an extra request for validating user permissions, several unrelated tests started failing.

It was found that the failure was due to the way these tests are doing assertions based on the axios mock history, now that there is a new request, the history has more than one item, and the validations are not passing.

There are about 34 test files that potentially have the issue, these do asserts like:

expect(axiosMock.history.post.length).toBe(1);
expect(axiosMock.history.post[0].data).toBe(...);

Now, because the useUserPermissions hook in https://github.com/openedx/frontend-app-authoring/pull/2685 is calling an extra endpoint, axiosMock.history.post.length becomes 2, and axiosMock.history.post[0] may be different than what the tests are expecting.

One possible approach for fixing this would be to wait for a specific history item with a specific url, instead of just accessing the first item in the history.

Example test that shows the issue here: https://github.com/WGU-Open-edX/frontend-app-authoring/blob/master/src/library-authoring/components/ComponentCard.test.tsx#L86

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/library-authoring/components/ComponentCard.test.tsx and inspect the axios mock history assertions around the linked example. Search the roughly 34 test files for assertions on axiosMock.history.post and update the affected checks to identify the intended request by URL. Done means the affected tests pass despite the additional permissions request.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend, testing
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.