Introduce testing library with cypress #1284
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
findByLabelTextdoesn't work from the root shadow DOM element which is why I've called it onchildren().This branch is based off of
update-cypress. If we're happy I will merge to main after that branch.Feedback wanted: