openedx / openedx/frontend-app-authoring
Refactor how the tests are set up on the TranscriptSettings test suite.
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 17
- Forks
- 218
- Avg merge
- 9d 20h
- Merged PRs (30d)
- 20
Description
There is a problem with how you're setting up userEvent in this test suite. If you change this test to it.only so it is the only test that runs, you'll see the test suite fails, because userEvent.setup() is only called in the beforeEach of the "default behaviors" tests, not every test.
src/files-and-videos/videos-page/transcript-settings/TranscriptSettings.test.jsx
TypeError: Cannot read properties of undefined (reading 'click')
223 | renderComponent(defaultProps);
224 | const orderButton = screen.getByText(messages.orderTranscriptsTitle.defaultMessage);
> 225 | await user.click(orderButton);
It's worth noting that the Testing Library folks say:
We discourage rendering or using any
userEventfunctions outside of the test itself - e.g. in abefore/afterhook - for reasons described in "Avoid Nesting When You're Testing".
However, I'm just pointing that out as a best practice for future reference. It does not make sense to refactor these tests along those lines as it would be too much work. But we do need to call setup() somewhere more correct, so that isolating tests with mechanisms like it.only doesn't cause them to fail.
Originally posted by @bradenmacdonald in https://github.com/openedx/frontend-app-authoring/pull/2277#discussion_r2208825893
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/files-and-videos/videos-page/transcript-settings/TranscriptSettings.test.jsx and run the suite with the affected test isolated using it.only. Inspect where userEvent.setup() is called and refactor the setup so isolated tests do not fail with an undefined user; the existing tests should pass afterward.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- frontend, testing-qa
- Issue type
- Refactor
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100