This repository was archived by the owner on Mar 5, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 14 files changed +132
-2
lines changed Expand file tree Collapse file tree 14 files changed +132
-2
lines changed Original file line number Diff line number Diff line change @@ -164,6 +164,7 @@ We have several subfolders in [examples](examples) folder that have complete pro
164164<!-- prettier-ignore-start -->
165165Folder Name | Description
166166--- | ---
167+ [ a11y] ( examples/a11y ) | Testing components' accessibility using [ cypress-axe] ( https://github.com/avanslaars/cypress-axe )
167168[ react-scripts] ( examples/react-scripts ) | A project using ` react-scripts ` with component tests in ` src ` folder
168169[ react-scripts-folder] ( examples/react-scripts-folder ) | A project using ` react-scripts ` with component tests in ` cypress/component `
169170[ tailwind] ( examples/tailwind ) | Testing styles built using [ Tailwind CSS] ( https://tailwindcss.com/ )
Original file line number Diff line number Diff line change @@ -31,6 +31,18 @@ workflows:
3131 name : Build folder 🏗
3232 command : npm run build
3333
34+ - cypress/run :
35+ name : Example A11y
36+ requires :
37+ - Install
38+ # each example installs "cypress-react-unit-test" as a local dependency (symlink)
39+ install-command : npm install
40+ verify-command : echo 'Already verified'
41+ no-workspace : true
42+ working_directory : examples/a11y
43+ command : npm test
44+ store_artifacts : true
45+
3446 - cypress/run :
3547 name : Example Babel
3648 requires :
@@ -239,10 +251,11 @@ workflows:
239251 requires :
240252 - Install
241253 - Test
242- - Example Sass
254+ - Example A11y
243255 - Example Babel
244- - Example React Scripts
245256 - Example Component Folder
257+ - Example React Scripts
258+ - Example Sass
246259 - Example Tailwind
247260 - Example Webpack options
248261 - Visual Sudoku
Original file line number Diff line number Diff line change 1+ package-lock = false
Original file line number Diff line number Diff line change 1+ # example: a11y
2+
3+ > Testing component accessibility
4+
5+ ``` shell
6+ npm install
7+ npm run cy:open
8+ # or just run headless tests
9+ npm test
10+ ```
11+
12+ Testing components following the [ React accessibility guide] ( https://reactjs.org/docs/accessibility.html ) using [ cypress-axe] ( https://github.com/avanslaars/cypress-axe ) plugin.
13+
14+ See the spec file [ cypress/component/spec.js] ( cypress/component/spec.js ) . For example, an ` <input> ` without a label is caught:
15+
16+ ``` js
17+ mount (< input type= " text" value= " John Smith" name= " name" / > )
18+ cy .checkA11y (' input' , {
19+ runOnly: {
20+ type: ' tag' ,
21+ values: [' wcag2a' ],
22+ },
23+ })
24+ ```
25+
26+ ![ Input without a label] ( images/missing-label.png )
27+
28+ You can click on the error to see more details in the DevTools console
29+
30+ ![ Error details] ( images/label-error.png )
Original file line number Diff line number Diff line change 1+ {
2+ "fixturesFolder" : false ,
3+ "testFiles" : " **/*spec.js" ,
4+ "viewportWidth" : 500 ,
5+ "viewportHeight" : 500 ,
6+ "experimentalComponentTesting" : true
7+ }
Original file line number Diff line number Diff line change 1+ /// <reference types="cypress" />
2+ import React from 'react'
3+ import { mount } from 'cypress-react-unit-test'
4+
5+ describe ( 'Accessibility' , ( ) => {
6+ before ( ( ) => {
7+ // https://github.com/avanslaars/cypress-axe
8+ cy . injectAxe ( )
9+ } )
10+
11+ // https://www.w3.org/WAI/standards-guidelines/aria/
12+ context ( 'aria' , ( ) => {
13+ // skip a failing test on purpose
14+ it . skip ( 'catches missing aria-* label' , ( ) => {
15+ mount ( < input type = "text" value = "John Smith" name = "name" /> )
16+ cy . checkA11y ( 'input' , {
17+ runOnly : {
18+ type : 'tag' ,
19+ values : [ 'wcag2a' ] ,
20+ } ,
21+ } )
22+ } )
23+
24+ it ( 'passes' , ( ) => {
25+ mount (
26+ < input
27+ type = "text"
28+ aria-label = "label text"
29+ aria-required = "true"
30+ value = "John Smith"
31+ name = "name"
32+ /> ,
33+ )
34+ cy . checkA11y ( 'input' , {
35+ runOnly : {
36+ type : 'tag' ,
37+ values : [ 'wcag2a' ] ,
38+ } ,
39+ } )
40+ } )
41+ } )
42+ } )
Original file line number Diff line number Diff line change 1+ /// <reference types="cypress" />
2+ describe ( 'integration spec' , ( ) => {
3+ it ( 'works' , ( ) => {
4+ expect ( 1 ) . to . equal ( 1 )
5+ } )
6+ } )
Original file line number Diff line number Diff line change 1+ // load file preprocessor that comes with this plugin
2+ // https://github.com/bahmutov/cypress-react-unit-test#install
3+ const preprocessor = require ( 'cypress-react-unit-test/plugins/react-scripts' )
4+ module . exports = ( on , config ) => {
5+ preprocessor ( on , config )
6+ // IMPORTANT to return the config object
7+ // with the any changed environment variables
8+ return config
9+ }
Original file line number Diff line number Diff line change 1+ require ( 'cypress-react-unit-test/support' )
2+ require ( 'cypress-axe' )
You can’t perform that action at this time.
0 commit comments