@@ -2,9 +2,12 @@ import {
2
2
fireEvent ,
3
3
isInaccessible ,
4
4
queries ,
5
+ buildQueries ,
6
+ queryAllByAttribute ,
5
7
screen ,
6
8
waitFor ,
7
9
waitForElementToBeRemoved ,
10
+ MatcherOptions ,
8
11
} from '../index'
9
12
10
13
const {
@@ -42,6 +45,42 @@ async function testQueries() {
42
45
await screen . findAllByText ( 'bar' , undefined , { timeout : 10 } )
43
46
}
44
47
48
+ async function testQueryHelpers ( ) {
49
+ const element = document . createElement ( 'div' )
50
+ const includesAutomationId = ( content : string , automationId : string ) =>
51
+ content . split ( / \s + / ) . some ( id => id === automationId )
52
+ const queryAllByAutomationId = (
53
+ container : HTMLElement ,
54
+ automationId : string | string [ ] ,
55
+ options ?: MatcherOptions ,
56
+ ) =>
57
+ queryAllByAttribute (
58
+ 'testId' ,
59
+ container ,
60
+ content =>
61
+ Array . isArray ( automationId )
62
+ ? automationId . every ( id => includesAutomationId ( content , id ) )
63
+ : includesAutomationId ( content , automationId ) ,
64
+ options ,
65
+ )
66
+ const [
67
+ queryByAutomationId ,
68
+ getAllByAutomationId ,
69
+ getByAutomationId ,
70
+ findAllByAutomationId ,
71
+ findByAutomationId ,
72
+ ] = buildQueries (
73
+ queryAllByAutomationId ,
74
+ ( ) => 'Multiple Error' ,
75
+ ( ) => 'Missing Error' ,
76
+ )
77
+ queryByAutomationId ( element , 'id' )
78
+ getAllByAutomationId ( element , 'id' )
79
+ getByAutomationId ( element , [ 'id' , 'automationId' ] )
80
+ findAllByAutomationId ( element , 'id' , { } , { timeout : 1000 } )
81
+ findByAutomationId ( element , 'id' , { } , { timeout : 1000 } )
82
+ }
83
+
45
84
async function testByRole ( ) {
46
85
const element = document . createElement ( 'button' )
47
86
element . setAttribute ( 'aria-hidden' , 'true' )
@@ -116,7 +155,11 @@ async function testWaitFors() {
116
155
117
156
element . innerHTML = '<span>apple</span>'
118
157
119
- await waitForElementToBeRemoved ( ( ) => getByText ( element , 'apple' ) , { interval : 3000 , container : element , timeout : 5000 } )
158
+ await waitForElementToBeRemoved ( ( ) => getByText ( element , 'apple' ) , {
159
+ interval : 3000 ,
160
+ container : element ,
161
+ timeout : 5000 ,
162
+ } )
120
163
await waitForElementToBeRemoved ( getByText ( element , 'apple' ) )
121
164
await waitForElementToBeRemoved ( getAllByText ( element , 'apple' ) )
122
165
}
0 commit comments