Coding task · JavaScript and React course · Module 13: Testing React
Practice: Interactive Components
For a checkbox the new value is in event.target.checked, not in event.target.value (the value of a checkbox is always the same string). aria-pressed turns a plain button into a toggle button: a screen reader says whether it is pressed, and React Testing Library lets you filter by that state with the pressed option. Each ToggleSwitch has its own state, so the two toggles work independently.
Task
Finish two components of the control panel. ToggleSwitch is a checkbox inside a label, so the test finds it with getByRole('checkbox', { name: 'Shields' }). ___BLANK1___: the checkbox is controlled, its checked state comes from the on state. ___BLANK2___: after a click the state takes the new checked value from the event object (the checked field of event.target), and the status next to it changes to on or off. NavigationList shows the travel destination buttons. ___BLANK3___: aria-pressed of a button is true only for the selected destination and false for the others, so the test finds the selected destination with getByRole('button', { pressed: true }).