@@ -172,13 +172,54 @@ test('should suggest img role w/ alt text', () => {
172
172
} )
173
173
174
174
test ( 'escapes regular expressions in suggestion' , ( ) => {
175
- renderIntoDocument (
176
- `<img src="foo.png" alt="The Problem (picture of a question mark)" data-testid="foo" />` ,
177
- )
175
+ const { container} = renderIntoDocument ( `
176
+ <label for="superInput">inp-t lab^l w{th c+ars to esc\\pe</label>
177
+ <input id="superInput" type="text" value="my super string +-('{}^$)" placeholder="should escape +-'(/" />
178
+ <p>
179
+ Loading ... (1)
180
+ </p>
181
+ <img src="foo.png" alt="The Problem (picture of a question mark)" data-testid="foo" />
182
+ ` )
178
183
179
184
expect ( ( ) => screen . getByTestId ( 'foo' ) ) . toThrowError (
180
185
/ g e t B y R o l e \( ' i m g ' , \{ n a m e : \/ t h e p r o b l e m \\ \( p i c t u r e o f a q u e s t i o n m a r k \\ \) \/ i \} \) / ,
181
186
)
187
+
188
+ expect (
189
+ getSuggestedQuery (
190
+ container . querySelector ( 'img' ) ,
191
+ 'get' ,
192
+ 'altText' ,
193
+ ) . toString ( ) ,
194
+ ) . toEqual ( `getByAltText(/the problem \\(picture of a question mark\\)/i)` )
195
+
196
+ expect ( getSuggestedQuery ( container . querySelector ( 'p' ) ) . toString ( ) ) . toEqual (
197
+ `getByText(/loading \\.\\.\\. \\(1\\)/i)` ,
198
+ )
199
+
200
+ expect (
201
+ getSuggestedQuery (
202
+ container . querySelector ( 'input' ) ,
203
+ 'get' ,
204
+ 'placeholderText' ,
205
+ ) . toString ( ) ,
206
+ ) . toEqual ( `getByPlaceholderText(/should escape \\+\\-'\\(\\//i)` )
207
+
208
+ expect (
209
+ getSuggestedQuery (
210
+ container . querySelector ( 'input' ) ,
211
+ 'get' ,
212
+ 'displayValue' ,
213
+ ) . toString ( ) ,
214
+ ) . toEqual ( `getByDisplayValue(/my super string \\+\\-\\('\\{\\}\\^\\$\\)/i)` )
215
+
216
+ expect (
217
+ getSuggestedQuery (
218
+ container . querySelector ( 'input' ) ,
219
+ 'get' ,
220
+ 'labelText' ,
221
+ ) . toString ( ) ,
222
+ ) . toEqual ( `getByLabelText(/inp\\-t lab\\^l w\\{th c\\+ars to esc\\\\pe/i)` )
182
223
} )
183
224
184
225
test ( 'should suggest getByLabelText when no role available' , ( ) => {
0 commit comments