Skip to content

Commit

Permalink
Merge pull request component-driven#4 from samcus/feature/run-parameters
Browse files Browse the repository at this point in the history
Add Configure Method, Add Context and Options Parameters
  • Loading branch information
avanslaars authored Mar 2, 2019
2 parents 22c002d + a8062b9 commit bb3ed83
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2,266 deletions.
20 changes: 18 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@ Cypress.Commands.add('injectAxe', () => {
})
})

Cypress.Commands.add('checkA11y', () => {
Cypress.Commands.add('configureAxe', (configurationOptions = {}) => {
cy.window({ log: false })
.then(win => {
return win.axe.run(win.document)
return win.axe.configure(configurationOptions)
})
})

Cypress.Commands.add('checkA11y', (context, options) => {
cy.window({ log: false })
.then(win => {
if (isEmptyObjectorNull(context)) context = undefined
if (isEmptyObjectorNull(options)) options = undefined
return win.axe.run(context ?
context = context :
context = win.document, options)
})
.then(({ violations }) => {
if (violations.length) {
Expand All @@ -34,3 +45,8 @@ Cypress.Commands.add('checkA11y', () => {
)
})
})

function isEmptyObjectorNull(value) {
if (value == null) return true
return Object.entries(value).length === 0 && value.constructor === Object
}
Loading

0 comments on commit bb3ed83

Please sign in to comment.