Skip to content

Conversation

@zetter-rpf
Copy link
Contributor

@zetter-rpf zetter-rpf commented Jan 9, 2026

Related to https://github.com/RaspberryPiFoundation/digital-editor-issues/issues/878

We're already using https://github.com/testing-library for our react unit tests code, the library for cypress brings the same benefits. It will allow us to write end to end tests that better mimic user behaviour by interacting with elements based on their role/text/labels rather than their classes. As well as making the specs easier to follow and de-coupled from our class names, it helps to ensure our site is accessible (e.g. form elements have labels).

To demonstrate this I've written added a new test to work with multiple files. If we like this approach, we can change over other specs as we write or update them.

Note that cypress testing library doesn't seem to have direct support for the Shadow DOM yet (see testing-library/dom-testing-library#413 ) but we still works if we load the shadow DOM using the cypress finder. One quirk I found is that findByLabelText doesn't work from the root shadow DOM element which is why I've called it on children().

This branch is based off of update-cypress. If we're happy I will merge to main after that branch.


Feedback wanted:

  • Do we think there's a benefit to using testing library for our cypress specs?
  • Are we happy to migrate them over gradually? Alternatively we could invest a bit of time to do them all at once (perhaps with the help of a coding agent).

@zetter-rpf zetter-rpf temporarily deployed to previews/1284/merge January 9, 2026 17:12 — with GitHub Actions Inactive
@zetter-rpf zetter-rpf force-pushed the introduce-testing-library-with-cypress branch from 6c60bd2 to 5002a96 Compare January 12, 2026 09:30
@zetter-rpf zetter-rpf temporarily deployed to previews/1284/merge January 12, 2026 09:30 — with GitHub Actions Inactive
@zetter-rpf
Copy link
Contributor Author

Note that this is failing because of #1285

@danhalson
Copy link
Contributor

Yes I like this approach, it's more in line with our unit tests, which is more intuitive...using copilot to migrate them makes sense, and will ensure we have a new baseline to work from.

it might be an idea to share this approach in a knowledge sharing session too, so everybody is onboard.

Copy link
Contributor

@danhalson danhalson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Base automatically changed from update-cypress to main January 12, 2026 11:32
We're already using @testing-library for our react code, the library for cypress brings the same benefits - it will allow us to write end to end tests that better mimic user behaviour by interacting with elements based on their role/text/labels rather than their classes. As well as making the specs easier to follow and de-coupled from our class names, it helps to ensure our site is accessible (i.e form elements have labels).

To demonstrate this I've written added a new test to work with multiple files. If we like this approach, we can change over other specs as we write or update them.

Note that cypress testing library doesn't seem to have direct support for the Shadow DOM yet (see testing-library/dom-testing-library#413 ) but we still works if we load the shadow DOM using the cypress finder.  One quirk I found is that `findByLabelText` doesn't work from the root shadow dom element which is why I've called it on `children()`.
cypress aliases let you share values between setup and files. See [1]

[1] https://docs.cypress.io/app/core-concepts/variables-and-aliases
@zetter-rpf zetter-rpf force-pushed the introduce-testing-library-with-cypress branch from 5002a96 to 84f6ec8 Compare January 12, 2026 11:35
@zetter-rpf zetter-rpf merged commit 829bb3e into main Jan 12, 2026
14 of 15 checks passed
@zetter-rpf zetter-rpf deleted the introduce-testing-library-with-cypress branch January 12, 2026 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants