From 58c497d944b0f07d27bfdd9e1ef46da49118da03 Mon Sep 17 00:00:00 2001 From: Kyrsten Kelly Date: Fri, 8 May 2020 10:53:14 -0500 Subject: [PATCH] feat: Add parameter for setting failure threshold --- README.md | 4 ++++ src/index.js | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3061f9a..52e7b8c 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,10 @@ Disables assertions based on violations and only logs violations to the console Reference : https://github.com/avanslaars/cypress-axe/issues/17 +###### failureThreshold (optional, defaults to 0) + +Allows you to configure the number of violations that will cause the assertion to fail. This should be used as a temporary measure while you address accessibility violations, but can help validate that you're not regressing as you progress towards 0 violations. + ### Examples #### Basic usage diff --git a/src/index.js b/src/index.js index 0135c01..84c810d 100644 --- a/src/index.js +++ b/src/index.js @@ -18,7 +18,8 @@ const checkA11y = ( context, options, violationCallback, - skipFailures = false + skipFailures = false, + failureThreshold = 0 ) => { cy.window({ log: false }) .then(win => { @@ -61,9 +62,9 @@ const checkA11y = ( }) .then(violations => { if (!skipFailures) { - assert.equal( + assert.isAtMost( violations.length, - 0, + failureThreshold, `${violations.length} accessibility violation${ violations.length === 1 ? '' : 's' } ${violations.length === 1 ? 'was' : 'were'} detected`