-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(switch): Redo switch tests in react-testing-library #386
Conversation
Test summaryRun details
View run in Cypress Dashboard ➡️ This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard |
These are caught in viz reg
Remove conditional testing for check/uncheck
getSwitch().click(); | ||
}); | ||
it('should be checked', () => { | ||
getSwitch().should('be.checked'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this duplication of RTL/enzyme tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cypress tests are about specifications from a user's perspective. This spec reads in full "Non-disabled Switch when the switch is clicked should be checked". Linking the given of the story being rendered, the when of the switch being clicked, and the then of the side effect of that action where the switch is now checked.
I might argue that "checked" is an implementation detail of a switch being "on", but there is a bit of controversy around how a "switch" should be labelled/read by screen readers from an accessibility standpoint. I don't remember the final say the role
attribute of a Switch
which effects how it will be read by a screen reader.
I personally avoid actions in unit-level tests including clicks. Most of the time firing a click
event is enough for the semantic action we'd call "click", but some components will expect other browser events in a specific order and some events aren't as simple as a "click". I leave that all for Cypress which has wiring for all that. In Cypress, a "click" includes other events normally associated with "click" like "mouseover". I've seen unit tests that try to recreate all that. Yuck.
I wouldn't worry about possible duplication in testing levels. Each serve a specific purpose.
Dang, TravisCI is slow! 10s isn't enough to verify a Storybook doc is loaded. |
Using Workday#372 as a canonical example
Specify checkbox as an input in test desc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very close 👍
Add ErrorType as a static member
Summary
Alright, lots of changes here:
jest-emotion
insetupTests
instead of locally inPageHeader.spec.tsx
Doing these tests revealed a few changes that we'll need to make (tracked in #387):
tabIndex={0}
, this is the default already.Switch.ErrorType.Alert
toErrorType
fromcanvas-kit-react-common
. It's kind of a pain to import that also just to useSwitch
.role
attribute a configurable prop. Instead ofcheckbox
it could be something likeswitch
.SwitchBackground
andSwitchCircle
to something more semantically correct likeSwitchTrack
andSwitchThumb
.