DEV Community

Cover image for Testing accessibility with Cypress

Testing accessibility with Cypress

stereobooster on June 01, 2019

In the previous post, we created an accessible React accordion component. Let's test it. I don't see much sense of writing unit tests for this kind...
Collapse
 
kodikos profile image
Jodi Winters

We're just writing tests for a really popular accessible page on the Internet. We have found an interesting one, checking for "accessible" content. If we have an element that's hidden by the zero'd dimensions trick so that it's still visible by a screen reader, cypress still think it's hidden, so a :visible or should('be.visible',...) isn't really a sufficient test. I'm wondering if you've determined a good practice for testing something like this?

Collapse
 
stereobooster profile image
stereobooster

I thought hidden (html5 attribute) means hidden to everyone. I need to double check, because I'm not sure

Collapse
 
kodikos profile image
Jodi Winters

I went looking myself, found webaim.org/techniques/css/invisibl.... However, I was wrong about which trick we were using, they're 1px blocks with overflow and the content is pushed away into the overflow. I'm not near my cypress at the mo, so I'll check and if there's still an issue, put up some proper detail on it :)
I think some custom should rules could really help with a11y.

Collapse
 
bhupendra1011 profile image
bhupendra

There is a great package to test a11y with cypress , you can follow the guide here.

However when I am trying to integrate , I get error : cy.injectAxe() is not a function.

Collapse
 
craigcarlyle profile image
Craig Carlyle

Very nice. We do something similar at my company. I wrote a Cypress command to run the aXe engine against our components as a sanity check as the final step. Here's a gist if you're interested.

Collapse
 
laistomazz profile image
Laís Tomaz

Instead of using cy.wait(100), change the default timeout property of the next command.

It will keep retrying and solve as soon as possible, instead of waiting a fixed amount of time.

Collapse
 
stereobooster profile image
stereobooster

Nice to know. Thanks

Collapse
 
aleccool213 profile image
Alec Brunelle

Thanks for this. I started to recently use Cypress and I never thought about accessibility testing with it :)