-
Notifications
You must be signed in to change notification settings - Fork 51.1k
Expand file tree
/
Copy pathReactDOMInvalidARIAHook-test.js
More file actions
152 lines (135 loc) · 5.21 KB
/
ReactDOMInvalidARIAHook-test.js
File metadata and controls
152 lines (135 loc) · 5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
*/
'use strict';
describe('ReactDOMInvalidARIAHook', () => {
let React;
let ReactDOMClient;
let mountComponent;
let act;
let assertConsoleErrorDev;
beforeEach(() => {
jest.resetModules();
React = require('react');
ReactDOMClient = require('react-dom/client');
act = require('internal-test-utils').act;
assertConsoleErrorDev =
require('internal-test-utils').assertConsoleErrorDev;
mountComponent = async function (props) {
const container = document.createElement('div');
const root = ReactDOMClient.createRoot(container);
await act(() => {
root.render(<div {...props} />);
});
};
});
describe('aria-* props', () => {
it('should allow valid aria-* props', async () => {
await mountComponent({'aria-label': 'Bumble bees'});
});
it('should allow new ARIA 1.3 attributes', async () => {
// Test aria-braillelabel
await mountComponent({'aria-braillelabel': 'Braille label text'});
// Test aria-brailleroledescription
await mountComponent({'aria-brailleroledescription': 'Navigation menu'});
// Test aria-colindextext
await mountComponent({'aria-colindextext': 'Column A'});
// Test aria-rowindextext
await mountComponent({'aria-rowindextext': 'Row 1'});
// Test multiple ARIA 1.3 attributes together
await mountComponent({
'aria-braillelabel': 'Braille text',
'aria-colindextext': 'First column',
'aria-rowindextext': 'First row',
});
});
it('should warn for one invalid aria-* prop', async () => {
await mountComponent({'aria-badprop': 'maybe'});
assertConsoleErrorDev([
'Invalid aria prop `aria-badprop` on <div> tag. ' +
'For details, see https://react.dev/link/invalid-aria-props\n' +
' in div (at **)',
]);
});
it('should warn for many invalid aria-* props', async () => {
await mountComponent({
'aria-badprop': 'Very tall trees',
'aria-malprop': 'Turbulent seas',
});
assertConsoleErrorDev([
'Invalid aria props `aria-badprop`, `aria-malprop` on <div> ' +
'tag. For details, see https://react.dev/link/invalid-aria-props\n' +
' in div (at **)',
]);
});
it('should warn for an improperly cased aria-* prop', async () => {
// The valid attribute name is aria-haspopup.
await mountComponent({'aria-hasPopup': 'true'});
assertConsoleErrorDev([
'Unknown ARIA attribute `aria-hasPopup`. ' +
'Did you mean `aria-haspopup`?\n' +
' in div (at **)',
]);
});
it('should warn for use of recognized camel case aria attributes', async () => {
// The valid attribute name is aria-haspopup.
await mountComponent({ariaHasPopup: 'true'});
assertConsoleErrorDev([
'Invalid ARIA attribute `ariaHasPopup`. ' +
'Did you mean `aria-haspopup`?\n' +
' in div (at **)',
]);
});
it('should warn for use of unrecognized camel case aria attributes', async () => {
// The valid attribute name is aria-haspopup.
await mountComponent({ariaSomethingInvalid: 'true'});
assertConsoleErrorDev([
'Invalid ARIA attribute `ariaSomethingInvalid`. ARIA ' +
'attributes follow the pattern aria-* and must be lowercase.\n' +
' in div (at **)',
]);
});
it('should warn when a valid aria-* attribute receives a NaN value', async () => {
await mountComponent({'aria-valuenow': NaN});
assertConsoleErrorDev([
'Received `NaN` for the `aria-valuenow` attribute. If this is expected, cast ' +
'the value to a string.\n' +
' in div (at **)',
]);
});
it('should warn when a string-type aria-* attribute receives a NaN value', async () => {
await mountComponent({'aria-label': NaN});
assertConsoleErrorDev([
'Received `NaN` for the `aria-label` attribute. If this is expected, cast ' +
'the value to a string.\n' +
' in div (at **)',
]);
});
it('should warn when a valid aria-* attribute receives an Infinity value', async () => {
await mountComponent({'aria-valuenow': Infinity});
assertConsoleErrorDev([
'Received `Infinity` for the `aria-valuenow` attribute. If this is expected, cast ' +
'the value to a string.\n' +
' in div (at **)',
]);
});
it('should warn when a valid aria-* attribute receives a -Infinity value', async () => {
await mountComponent({'aria-valuemin': -Infinity});
assertConsoleErrorDev([
'Received `-Infinity` for the `aria-valuemin` attribute. If this is expected, cast ' +
'the value to a string.\n' +
' in div (at **)',
]);
});
it('should not warn for valid numeric values in aria-* attributes', async () => {
await mountComponent({'aria-valuenow': 42});
await mountComponent({'aria-level': 3});
await mountComponent({'aria-colcount': -1});
});
});
});