@@ -29,7 +29,10 @@ export type Scenario = {
29
29
shouldIgnoreViolation ?: ( violation : Result ) => boolean ;
30
30
} ;
31
31
32
- async function testScenario ( elementOrWrapper : VNode | ReactWrapper ) {
32
+ async function testScenario (
33
+ elementOrWrapper : VNode | ReactWrapper ,
34
+ { shouldIgnoreViolation } : Pick < Scenario , 'shouldIgnoreViolation' > ,
35
+ ) {
33
36
const container = document . createElement ( 'div' ) ;
34
37
document . body . appendChild ( container ) ;
35
38
@@ -52,10 +55,16 @@ async function testScenario(elementOrWrapper: VNode | ReactWrapper) {
52
55
// or "inapplicable" (no relevant HTML elements found).
53
56
resultTypes : [ 'violations' ] ,
54
57
} ) ;
58
+
59
+ let violations = results . violations ;
60
+ if ( shouldIgnoreViolation ) {
61
+ violations = violations . filter ( v => ! shouldIgnoreViolation ( v ) ) ;
62
+ }
63
+
55
64
wrapper . unmount ( ) ;
56
65
container . remove ( ) ;
57
66
58
- return results . violations ;
67
+ return violations ;
59
68
}
60
69
61
70
function asArray < T > ( itemOrList : T | T [ ] ) : T [ ] {
@@ -95,14 +104,13 @@ export function checkAccessibility(
95
104
) ;
96
105
}
97
106
98
- const violations = await testScenario ( elementOrWrapper ) ;
99
- const filteredViolations = shouldIgnoreViolation
100
- ? violations . filter ( v => ! shouldIgnoreViolation ( v ) )
101
- : violations ;
102
- for ( const violation of filteredViolations ) {
107
+ const violations = await testScenario ( elementOrWrapper , {
108
+ shouldIgnoreViolation,
109
+ } ) ;
110
+ for ( const violation of violations ) {
103
111
console . error ( 'axe-core violation' , JSON . stringify ( violation , null , 2 ) ) ;
104
112
}
105
- if ( filteredViolations . length > 0 ) {
113
+ if ( violations . length > 0 ) {
106
114
throw new Error ( `Scenario "${ name } " has accessibility violations` ) ;
107
115
}
108
116
}
0 commit comments