Skip to content

Commit 7622057

Browse files
mchamwmcode
authored andcommitted
fixed readme example
1 parent a94f449 commit 7622057

File tree

1 file changed

+33
-36
lines changed

1 file changed

+33
-36
lines changed

README.md

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ Test accessibility with [axe-core](https://github.com/dequelabs/axe-core) in [Cy
88
>
99
> **Reasons**: to upgrade dependencies (i.e. `Cypress ^7` & `axe-core ^4`) and try out some of the suggesions in [RFC 75](https://github.com/component-driven/cypress-axe/issues/75) 👀
1010
11-
1211
1. [Installation and Setup](#Installation-and-Setup)
13-
- [Typescript](#TypeScript)
12+
- [Typescript](#TypeScript)
1413
2. [Examples](#Examples)
15-
- [Simple](#Simple)
16-
- [Customised](#Customised)
14+
- [Simple](#Simple)
15+
- [Customised](#Customised)
1716
3. [Commands](#Commands)
18-
- [cy.injectAxe](#cyinjectAxe)
19-
- [cy.checkA11y](#cycheckA11y)
20-
- [cy.configureCypressAxe](#cyconfigureCypressAxe)
21-
- [cy.configureAxe](#cyconfigureAxe)
17+
- [cy.injectAxe](#cyinjectAxe)
18+
- [cy.checkA11y](#cycheckA11y)
19+
- [cy.configureCypressAxe](#cyconfigureCypressAxe)
20+
- [cy.configureAxe](#cyconfigureAxe)
2221

2322
# Installation and Setup
23+
2424
1. **Install** required packages. Assuming you have Cypress installed already, you will only need to:
2525

2626
```sh
@@ -34,35 +34,35 @@ import 'cypress-axe-core'
3434
```
3535

3636
3. **Enable** results logging by defining cy.tasks in `cypress/plugins/index.js` file:
37+
3738
```js
3839
module.exports = (on, config) => {
39-
on('task', {
40-
log(message) {
41-
console.log(message);
42-
return null;
43-
},
44-
45-
table(message) {
46-
console.table(message);
47-
return null;
48-
},
49-
});
50-
};
40+
on('task', {
41+
log(message) {
42+
console.log(message)
43+
return null
44+
},
45+
46+
table(message) {
47+
console.table(message)
48+
return null
49+
}
50+
})
51+
}
5152
```
53+
5254
> **NOTE**: You can control how results are displayed via [the `violationsCallback` config option](#cyconfigureCypressAxe)
5355
5456
After following the steps above (_and defining cy.tasks_), violations will be displayed as follows:
55-
- Cypress
56-
![Default Cypress output](assets/cypressOutputSample.png)
5757

58-
- Terminal
59-
![Default terminal output](assets/terminalOutputSample.png)
58+
- Cypress ![Default Cypress output](assets/cypressOutputSample.png)
6059

61-
- Browser
62-
![Default browser console output](assets/browserOutputSample.png)
60+
- Terminal ![Default terminal output](assets/terminalOutputSample.png)
6361

62+
- Browser ![Default browser console output](assets/browserOutputSample.png)
6463

6564
### TypeScript
65+
6666
If you’re using TypeScript, add `cypress-axe-core` types to your Cypress’s `tsconfig.json` file:
6767

6868
```json
@@ -94,20 +94,15 @@ it('passes axe', () => {
9494

9595
## Customised
9696

97-
Leveraging ([Cypress commands](https://docs.cypress.io/api/cypress-api/custom-commands)) You can either:
98-
99-
- Overwrite `cy.checkA11y` _or_
100-
- Wrap it in your own custom command
101-
102-
then pass it a `shouldFailFn` function to decide which rules should fail. For example, only assert against _serious_ & _critical_ violations but ignore _color-contrast_ rule.
103-
97+
Leveraging [Cypress commands](https://docs.cypress.io/api/cypress-api/custom-commands), you can create your own custom command that calls `cy.checkA11y` with the config you want.
98+
For example, if you only want to assert against _serious_ & _critical_ violations but ignore _color-contrast_ rule, you can do something like this:
10499
```js
105100
// cypress/support/commands.js
106101
Cypress.Commands.add(
107102
'checkAxeViolations',
108103
{ prevSubject: 'optional' },
109-
(subject, options, label) => {
110-
return cy.checkA11y(
104+
(context, options, label) => {
105+
cy.wrap(context).checkA11y(
111106
{
112107
shouldFailFn: violations =>
113108
violations.filter(
@@ -151,14 +146,16 @@ beforeEach(() => {
151146
When not chained to another element, it will run against the whole document. You can have it at the end of your test (after other interaction assertions) so it checks against all possible violations. It accepts the same (optional) config object that [`cy.configureCypressAxe`](#cyconfigureCypressAxe) accepts
152147

153148
**Note**: if you have a toggle-able element i.e. a side menu, make sure it's on (shown) by the time `cy.checkA11y` is called, otherwise you might end up with some false-positive cases. Or, you can target those elements directly to make sure they're tested
149+
154150
```js
155-
cy.get('#menu-button').click();
151+
cy.get('#menu-button').click()
156152
cy.get('#side-menu-container').checkA11y()
157153
```
158154

159155
## cy.configureCypressAxe
160156

161157
Instead of wrapping or overwriting `cy.checkA11y`, you can configure it. It accepts the following:
158+
162159
- `axeOptions` passed to axe-core.
163160
- `shouldFailFn` function that returns array of violations to check for.
164161
- `skipFailures` if true, it will log the violations but not assert against them.

0 commit comments

Comments
 (0)