File tree 7 files changed +112
-23
lines changed 7 files changed +112
-23
lines changed Original file line number Diff line number Diff line change 54
54
]
55
55
},
56
56
"devDependencies" : {
57
- "@chialab/vitest-axe" : " ^0.18.1" ,
58
57
"@matrix-widget-toolkit/testing" : " 2.5.0" ,
59
58
"@testing-library/dom" : " ^10.4.0" ,
60
59
"@testing-library/jest-dom" : " ^6.5.0" ,
Original file line number Diff line number Diff line change 20
20
// learn more: https://github.com/testing-library/jest-dom
21
21
import '@testing-library/jest-dom/vitest' ;
22
22
23
- import vitestAxeMatchers from '@chialab/vitest-axe' ;
24
- import matchers from '@testing-library/jest-dom/matchers' ;
25
- import '@testing-library/jest-dom/vitest' ;
26
23
import { TextDecoder , TextEncoder } from 'util' ;
27
24
import { expect , vi } from 'vitest' ;
28
25
29
- expect . extend ( matchers ) ;
30
-
31
26
// Make sure to initialize i18n (see mock below)
27
+ import { AxeResults } from 'axe-core' ;
32
28
import './i18n' ;
33
29
34
30
// Add support for axe
35
- expect . extend ( vitestAxeMatchers ) ;
31
+ expect . extend ( {
32
+ toHaveNoViolations ( results : AxeResults ) {
33
+ const violations = results . violations ?? [ ] ;
34
+
35
+ return {
36
+ pass : violations . length === 0 ,
37
+ actual : violations ,
38
+ message ( ) {
39
+ if ( violations . length === 0 ) {
40
+ return '' ;
41
+ }
42
+
43
+ return `Expected no accessibility violations but received some.
44
+
45
+ ${ violations
46
+ . map (
47
+ ( violation ) => `[${ violation . impact } ] ${ violation . id }
48
+ ${ violation . description }
49
+ ${ violation . helpUrl }
50
+ ` ,
51
+ )
52
+ . join ( '\n' ) }
53
+ ` ;
54
+ } ,
55
+ } ;
56
+ } ,
57
+ } ) ;
36
58
37
59
// Use a different configuration for i18next during tests
38
60
vi . mock ( './i18n' , async ( ) => {
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2024 Nordeck IT + Consulting GmbH
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import 'vitest' ;
18
+
19
+ interface AxeMatchers < R = unknown > {
20
+ toHaveNoViolations : ( ) => R ;
21
+ }
22
+
23
+ declare module 'vitest' {
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
+ interface Assertion < T = any > extends AxeMatchers < T > { }
26
+ interface AsymmetricMatchersContaining extends AxeMatchers { }
27
+ }
Original file line number Diff line number Diff line change 8
8
"module" : " ./src/index.ts" ,
9
9
"types" : " ./src/index.ts" ,
10
10
"devDependencies" : {
11
- "@chialab/vitest-axe" : " ^0.18.1" ,
12
11
"@testing-library/jest-dom" : " ^6.5.0" ,
13
12
"@testing-library/react" : " ^16.0.1" ,
14
13
"@testing-library/user-event" : " ^14.5.2" ,
Original file line number Diff line number Diff line change 21
21
import '@testing-library/jest-dom/vitest' ;
22
22
23
23
// Make sure to initialize i18n (see mock below)
24
- import vitestAxeMatchers from '@chialab/vitest-axe' ;
25
24
import i18n from 'i18next' ;
25
+
26
+ import { AxeResults } from 'axe-core' ;
26
27
import { initReactI18next } from 'react-i18next' ;
27
28
import { expect } from 'vitest' ;
28
29
@@ -35,4 +36,30 @@ i18n.use(initReactI18next).init({
35
36
} ) ;
36
37
37
38
// Add support for axe
38
- expect . extend ( vitestAxeMatchers ) ;
39
+ expect . extend ( {
40
+ toHaveNoViolations ( results : AxeResults ) {
41
+ const violations = results . violations ?? [ ] ;
42
+
43
+ return {
44
+ pass : violations . length === 0 ,
45
+ actual : violations ,
46
+ message ( ) {
47
+ if ( violations . length === 0 ) {
48
+ return '' ;
49
+ }
50
+
51
+ return `Expected no accessibility violations but received some.
52
+
53
+ ${ violations
54
+ . map (
55
+ ( violation ) => `[${ violation . impact } ] ${ violation . id }
56
+ ${ violation . description }
57
+ ${ violation . helpUrl }
58
+ ` ,
59
+ )
60
+ . join ( '\n' ) }
61
+ ` ;
62
+ } ,
63
+ } ;
64
+ } ,
65
+ } ) ;
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2024 Nordeck IT + Consulting GmbH
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import 'vitest' ;
18
+
19
+ interface AxeMatchers < R = unknown > {
20
+ toHaveNoViolations : ( ) => R ;
21
+ }
22
+
23
+ declare module 'vitest' {
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
+ interface Assertion < T = any > extends AxeMatchers < T > { }
26
+ interface AsymmetricMatchersContaining extends AxeMatchers { }
27
+ }
Original file line number Diff line number Diff line change 326
326
human-id "^1.0.2"
327
327
prettier "^2.7.1"
328
328
329
- " @chialab/vitest-axe@^0.18.1 " :
330
- version "0.18.1"
331
- resolved "https://registry.yarnpkg.com/@chialab/vitest-axe/-/vitest-axe-0.18.1.tgz#4d6a3ae3628bc3222b4640295023445e0e530619"
332
- integrity sha512-kdEwEdb6ill2i3Vjm/txJiWzBRES04HowNIzk9KUXy4VH35BXQpfdlNrb8p5c5vztZr0CFuUUyPhQVSBLjateg==
333
-
334
329
" @emotion/babel-plugin@^11.12.0 " :
335
330
version "11.12.0"
336
331
resolved "https://registry.yarnpkg.com/@emotion/babel-plugin/-/babel-plugin-11.12.0.tgz#7b43debb250c313101b3f885eba634f1d723fcc2"
1567
1562
semver "^7.6.0"
1568
1563
ts-api-utils "^1.3.0"
1569
1564
1570
- " @typescript-eslint/[email protected] " , "@typescript-eslint/utils@^6.0.0 || ^7.0.0 || ^8.0.0" :
1565
+ " @typescript-eslint/[email protected] " :
1571
1566
version "8.4.0"
1572
1567
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-8.4.0.tgz#35c552a404858c853a1f62ba6df2214f1988afc3"
1573
1568
integrity sha512-swULW8n1IKLjRAgciCkTCafyTHHfwVQFt8DovmaF69sKbOxTSFMmIZaSHjqO9i/RV0wIblaawhzvtva8Nmm7lQ==
@@ -2905,13 +2900,6 @@ eslint-config-prettier@^9.1.0:
2905
2900
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz#31af3d94578645966c082fcb71a5846d3c94867f"
2906
2901
integrity sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw==
2907
2902
2908
- eslint-plugin-jest@^28.8.2 :
2909
- version "28.8.3"
2910
- resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-28.8.3.tgz#c5699bba0ad06090ad613535e4f1572f4c2567c0"
2911
- integrity sha512-HIQ3t9hASLKm2IhIOqnu+ifw7uLZkIlR7RYNv7fMcEi/p0CIiJmfriStQS2LDkgtY4nyLbIZAD+JL347Yc2ETQ==
2912
- dependencies :
2913
- " @typescript-eslint/utils" " ^6.0.0 || ^7.0.0 || ^8.0.0"
2914
-
2915
2903
eslint-plugin-notice@^1.0.0 :
2916
2904
version "1.0.0"
2917
2905
resolved "https://registry.yarnpkg.com/eslint-plugin-notice/-/eslint-plugin-notice-1.0.0.tgz#4b98ffdf2274d10f34a4231a74efafdecad6cde4"
You can’t perform that action at this time.
0 commit comments