@@ -4,7 +4,6 @@ import { ReactTestInstance } from 'react-test-renderer';
44import {
55 render ,
66 fireEvent ,
7- shallow ,
87 flushMicrotasksQueue ,
98 waitFor ,
109 act ,
@@ -31,86 +30,89 @@ const TestComponent = () => (
3130
3231const tree = render ( < TestComponent /> ) ;
3332
34- // getByAPI tests
35- const getByType : ReactTestInstance = tree . UNSAFE_getByType ( View ) ;
36- const getByTypeWithRequiredProps : ReactTestInstance = tree . UNSAFE_getByType (
37- ElementWithRequiredProps
38- ) ;
39- const getByTextString : ReactTestInstance = tree . getByText ( '<View />' ) ;
40- const getByTextRegExp : ReactTestInstance = tree . getByText ( / V i e w / g) ;
41- const getByPlaceholderString : ReactTestInstance = tree . getByPlaceholder (
42- 'my placeholder'
43- ) ;
44- const getByPlaceholderRegExp : ReactTestInstance = tree . getByPlaceholder (
45- / p l a c e h o l d e r / g
46- ) ;
47- const getByDisplayValueString : ReactTestInstance = tree . getByDisplayValue (
48- 'my value'
49- ) ;
50- const getByDisplayValueRegExp : ReactTestInstance = tree . getByDisplayValue (
51- / v a l u e / g
52- ) ;
53- const getByProps : ReactTestInstance = tree . UNSAFE_getByProps ( { value : 2 } ) ;
54- const getByTestId : ReactTestInstance = tree . getByTestId ( 'test-id' ) ;
55- const getAllByTestId : ReactTestInstance [ ] = tree . getAllByTestId ( 'test-id' ) ;
56- const getAllByType : Array < ReactTestInstance > = tree . UNSAFE_getAllByType ( View ) ;
57- const getAllByTypeWithRequiredProps : Array < ReactTestInstance > = tree . UNSAFE_getAllByType (
58- ElementWithRequiredProps
59- ) ;
60- const getAllByTextString : Array < ReactTestInstance > = tree . getAllByText (
61- '<View />'
62- ) ;
63- const getAllByTextRegExp : Array < ReactTestInstance > = tree . getAllByText ( / T e x t / g) ;
64- const getAllByProps : Array < ReactTestInstance > = tree . UNSAFE_getAllByProps ( {
65- value : 2 ,
66- } ) ;
33+ // getBy API
34+ const getBy : ReactTestInstance [ ] = [
35+ tree . getByText ( '<View />' ) ,
36+ tree . getByText ( / V i e w / g) ,
37+ tree . getByPlaceholder ( 'my placeholder' ) ,
38+ tree . getByPlaceholder ( / p l a c e h o l d e r / g) ,
39+ tree . getByDisplayValue ( 'my value' ) ,
40+ tree . getByDisplayValue ( / v a l u e / g) ,
41+ tree . getByTestId ( 'test-id' ) ,
42+ tree . getByA11yLabel ( 'label' ) ,
43+ tree . getByA11yHint ( 'label' ) ,
44+ tree . getByA11yRole ( 'button' ) ,
45+ tree . getByA11yStates ( 'selected' ) ,
46+ tree . getByA11yStates ( [ 'selected' ] ) ,
47+ tree . getByA11yState ( { busy : true } ) ,
48+ tree . getByA11yValue ( { min : 10 } ) ,
49+ tree . UNSAFE_getByType ( View ) ,
50+ tree . UNSAFE_getByType ( ElementWithRequiredProps ) ,
51+ tree . UNSAFE_getByProps ( { value : 2 } ) ,
52+ ] ;
6753
68- // queuryByAPI tests
69- const queryByType : ReactTestInstance | null = tree . UNSAFE_queryByType ( View ) ;
70- const queryByTypeWithRequiredProps : ReactTestInstance | null = tree . UNSAFE_queryByType (
71- ElementWithRequiredProps
72- ) ;
73- const queryByTextString : ReactTestInstance | null = tree . queryByText ( 'View' ) ;
74- const queryByTextRegExp : ReactTestInstance | null = tree . queryByText ( / V i e w / g) ;
75- const queryByPlaceholderString : ReactTestInstance | null = tree . queryByPlaceholder (
76- 'my placeholder'
77- ) ;
78- const queryByPlaceholderRegExp : ReactTestInstance | null = tree . queryByPlaceholder (
79- / p l a c e h o l d e r / g
80- ) ;
81- const queryByDisplayValueString : ReactTestInstance | null = tree . queryByDisplayValue (
82- 'my value'
83- ) ;
84- const queryByDisplayValueRegExp : ReactTestInstance | null = tree . queryByDisplayValue (
85- / v a l u e / g
86- ) ;
87- const queryByProps : ReactTestInstance | null = tree . UNSAFE_queryByProps ( {
88- value : 2 ,
89- } ) ;
90- const queryByTestId : ReactTestInstance | null = tree . queryByTestId ( 'test-id' ) ;
91- const queryAllByTestId : ReactTestInstance [ ] | null = tree . queryAllByTestId (
92- 'test-id'
93- ) ;
94- const queryAllByType : Array < ReactTestInstance > = tree . UNSAFE_queryAllByType (
95- View
96- ) ;
97- const queryAllByTypeWithRequiredProps : Array < ReactTestInstance > = tree . UNSAFE_queryAllByType (
98- ElementWithRequiredProps
99- ) ;
100- const queryAllByTextString : Array < ReactTestInstance > = tree . queryAllByText (
101- 'View'
102- ) ;
103- const queryAllByTextRegExp : Array < ReactTestInstance > = tree . queryAllByText (
104- / V i e w / g
105- ) ;
106- const queryAllByDisplayValueString : Array < ReactTestInstance > = tree . queryAllByDisplayValue (
107- 'View'
108- ) ;
109- const queryAllByDisplayValueRegExp : Array < ReactTestInstance > = tree . queryAllByDisplayValue (
110- / V i e w / g
111- ) ;
54+ const getAllBy : ReactTestInstance [ ] [ ] = [
55+ tree . getAllByText ( '<View />' ) ,
56+ tree . getAllByText ( / T e x t / g) ,
57+ tree . getAllByPlaceholder ( 'my placeholder' ) ,
58+ tree . getAllByPlaceholder ( / p l a c e h o l d e r / g) ,
59+ tree . getAllByDisplayValue ( 'my value' ) ,
60+ tree . getAllByDisplayValue ( / v a l u e / g) ,
61+ tree . getAllByTestId ( 'test-id' ) ,
62+ tree . getAllByA11yLabel ( 'label' ) ,
63+ tree . getAllByA11yHint ( 'label' ) ,
64+ tree . getAllByA11yRole ( 'button' ) ,
65+ tree . getAllByA11yStates ( 'selected' ) ,
66+ tree . getAllByA11yStates ( [ 'selected' ] ) ,
67+ tree . getAllByA11yState ( { busy : true } ) ,
68+ tree . getAllByA11yValue ( { min : 10 } ) ,
69+ tree . UNSAFE_getAllByType ( View ) ,
70+ tree . UNSAFE_getAllByType ( ElementWithRequiredProps ) ,
71+ tree . UNSAFE_getAllByProps ( { value : 2 } ) ,
72+ ] ;
73+
74+ // queryBy API
75+ const queryBy : Array < ReactTestInstance | null > = [
76+ tree . queryByText ( 'View' ) ,
77+ tree . queryByText ( / V i e w / g) ,
78+ tree . queryByPlaceholder ( 'my placeholder' ) ,
79+ tree . queryByPlaceholder ( / p l a c e h o l d e r / g) ,
80+ tree . queryByDisplayValue ( 'my value' ) ,
81+ tree . queryByDisplayValue ( / v a l u e / g) ,
82+ tree . queryByTestId ( 'test-id' ) ,
83+ tree . queryByA11yHint ( 'label' ) ,
84+ tree . queryByA11yLabel ( 'label' ) ,
85+ tree . queryByA11yRole ( 'button' ) ,
86+ tree . queryByA11yStates ( 'selected' ) ,
87+ tree . queryByA11yStates ( [ 'selected' ] ) ,
88+ tree . queryByA11yState ( { busy : true } ) ,
89+ tree . queryByA11yValue ( { min : 10 } ) ,
90+ tree . UNSAFE_queryByType ( View ) ,
91+ tree . UNSAFE_queryByType ( ElementWithRequiredProps ) ,
92+ tree . UNSAFE_queryByProps ( { value : 2 } ) ,
93+ ] ;
11294
113- // findBy API tests
95+ const queryAllBy : ReactTestInstance [ ] [ ] = [
96+ tree . queryAllByText ( 'View' ) ,
97+ tree . queryAllByText ( / V i e w / g) ,
98+ tree . queryAllByPlaceholder ( 'my placeholder' ) ,
99+ tree . queryAllByPlaceholder ( / p l a c e h o l d e r / g) ,
100+ tree . queryAllByDisplayValue ( 'my value' ) ,
101+ tree . queryAllByDisplayValue ( / v a l u e / g) ,
102+ tree . queryAllByTestId ( 'test-id' ) ,
103+ tree . queryAllByA11yLabel ( 'label' ) ,
104+ tree . queryAllByA11yHint ( 'label' ) ,
105+ tree . queryAllByA11yRole ( 'button' ) ,
106+ tree . queryAllByA11yStates ( 'selected' ) ,
107+ tree . queryAllByA11yStates ( [ 'selected' ] ) ,
108+ tree . queryAllByA11yState ( { busy : true } ) ,
109+ tree . queryAllByA11yValue ( { min : 10 } ) ,
110+ tree . UNSAFE_queryAllByType ( View ) ,
111+ tree . UNSAFE_queryAllByType ( ElementWithRequiredProps ) ,
112+ tree . UNSAFE_queryAllByProps ( { value : 2 } ) ,
113+ ] ;
114+
115+ // findBy API
114116const findBy : Promise < ReactTestInstance > [ ] = [
115117 tree . findByText ( 'View' ) ,
116118 tree . findByText ( 'View' , { timeout : 10 , interval : 10 } ) ,
@@ -153,6 +155,8 @@ const findAllBy: Promise<ReactTestInstance[]>[] = [
153155 tree . findAllByDisplayValue ( / V i e w / g, { timeout : 10 , interval : 10 } ) ,
154156 tree . findAllByTestId ( 'test-id' ) ,
155157 tree . findAllByTestId ( 'test-id' , { timeout : 10 , interval : 10 } ) ,
158+ tree . findAllByA11yLabel ( 'label' ) ,
159+ tree . findAllByA11yLabel ( 'label' , { timeout : 10 , interval : 10 } ) ,
156160 tree . findAllByA11yHint ( 'label' ) ,
157161 tree . findAllByA11yHint ( 'label' , { timeout : 10 , interval : 10 } ) ,
158162 tree . findAllByA11yState ( { busy : true } ) ,
@@ -161,105 +165,50 @@ const findAllBy: Promise<ReactTestInstance[]>[] = [
161165 tree . findAllByA11yValue ( { min : 10 } , { timeout : 10 , interval : 10 } ) ,
162166] ;
163167
164- // Accessibility queries
165- const getByA11yLabel : ReactTestInstance = tree . getByA11yLabel ( 'label' ) ;
166- const getAllByA11yLabel : Array < ReactTestInstance > = tree . getAllByA11yLabel (
167- 'label'
168- ) ;
169- const queryByA11yLabel : ReactTestInstance = tree . queryByA11yLabel ( 'label' ) ;
170- const queryAllByA11yLabel : Array < ReactTestInstance > = tree . queryAllByA11yLabel (
171- 'label'
172- ) ;
173-
174- const getByA11yHint : ReactTestInstance = tree . getByA11yHint ( 'label' ) ;
175- const getAllByA11yHint : Array < ReactTestInstance > = tree . getAllByA11yHint (
176- 'label'
177- ) ;
178- const queryByA11yHint : ReactTestInstance = tree . queryByA11yHint ( 'label' ) ;
179- const queryAllByA11yHint : Array < ReactTestInstance > = tree . queryAllByA11yHint (
180- 'label'
181- ) ;
182-
183- const getByA11yRole : ReactTestInstance = tree . getByA11yRole ( 'button' ) ;
184- const getAllByA11yRole : Array < ReactTestInstance > = tree . getAllByA11yRole (
185- 'button'
186- ) ;
187- const queryByA11yRole : ReactTestInstance = tree . queryByA11yRole ( 'button' ) ;
188- const queryAllByA11yRole : Array < ReactTestInstance > = tree . queryAllByA11yRole (
189- 'button'
190- ) ;
191-
192- const getByA11yStates : ReactTestInstance = tree . getByA11yStates ( 'selected' ) ;
193- const getByA11yStatesArray : ReactTestInstance = tree . getByA11yStates ( [
194- 'selected' ,
195- ] ) ;
196- const getAllByA11yStates : Array < ReactTestInstance > = tree . getAllByA11yStates (
197- 'selected'
198- ) ;
199- const getAllByA11yStatesArray : Array < ReactTestInstance > = tree . getAllByA11yStates (
200- [ 'selected' ]
201- ) ;
202- const queryByA11yStates : ReactTestInstance = tree . queryByA11yStates ( 'selected' ) ;
203- const queryByA11yStatesArray : ReactTestInstance = tree . queryByA11yStates ( [
204- 'selected' ,
205- ] ) ;
206- const queryAllByA11yStates : Array < ReactTestInstance > = tree . queryAllByA11yStates (
207- 'selected'
208- ) ;
209- const queryAllByA11yStatesArray : Array < ReactTestInstance > = tree . queryAllByA11yStates (
210- [ 'selected' ]
211- ) ;
212-
213- const getByA11yState : ReactTestInstance = tree . getByA11yState ( { busy : true } ) ;
214- const getAllByA11yState : Array < ReactTestInstance > = tree . getAllByA11yState ( {
215- busy : true ,
216- } ) ;
217- const queryByA11yState : ReactTestInstance = tree . queryByA11yState ( {
218- busy : true ,
219- } ) ;
220- const queryAllByA11yState : Array < ReactTestInstance > = tree . queryAllByA11yState ( {
221- busy : true ,
222- } ) ;
223-
224- const getByA11yValue : ReactTestInstance = tree . getByA11yValue ( { min : 10 } ) ;
225- const getAllByA11yValue : Array < ReactTestInstance > = tree . getAllByA11yValue ( {
226- min : 10 ,
227- } ) ;
228- const queryByA11yValue : ReactTestInstance = tree . queryByA11yValue ( { min : 10 } ) ;
229- const queryAllByA11yValue : Array < ReactTestInstance > = tree . queryAllByA11yValue ( {
230- min : 10 ,
231- } ) ;
232-
168+ // debug API
233169const debugFn = tree . debug ( ) ;
234170const debugFnWithMessage = tree . debug ( 'my message' ) ;
235171
172+ // update API
236173tree . update ( < View /> ) ;
237174tree . rerender ( < View /> ) ;
238175tree . unmount ( ) ;
239176
240- // fireEvent API tests
241- fireEvent ( getByA11yLabel , 'press' ) ;
242- fireEvent ( getByA11yLabel , 'press' , 'data' ) ;
243- fireEvent ( getByA11yLabel , 'press' , 'param1' , 'param2' ) ;
244- fireEvent . press ( getByA11yLabel ) ;
245- fireEvent . changeText ( getByA11yLabel , 'string' ) ;
246- fireEvent . scroll ( getByA11yLabel , 'eventData' ) ;
177+ // fireEvent API
178+ const element : ReactTestInstance = tree . getByText ( 'text' ) ;
179+ fireEvent ( element , 'press' ) ;
180+ fireEvent ( element , 'press' , 'data' ) ;
181+ fireEvent ( element , 'press' , 'param1' , 'param2' ) ;
182+ fireEvent . press ( element ) ;
183+ fireEvent . changeText ( element , 'string' ) ;
184+ fireEvent . scroll ( element , 'eventData' ) ;
247185
248- // shallow API
249- const shallowTree : { output : React . ReactElement < any > } = shallow (
250- < TestComponent />
251- ) ;
186+ // waitFor API
187+ const waitGetBy : Promise < ReactTestInstance > [ ] = [
188+ waitFor < ReactTestInstance > ( ( ) => tree . getByA11yLabel ( 'label' ) ) ,
189+ waitFor < ReactTestInstance > ( ( ) => tree . getByA11yLabel ( 'label' ) , {
190+ timeout : 10 ,
191+ } ) ,
192+ waitFor < ReactTestInstance > ( ( ) => tree . getByA11yLabel ( 'label' ) , {
193+ timeout : 100 ,
194+ interval : 10 ,
195+ } ) ,
196+ ] ;
252197
253- const waitForFlush : Promise < any > = flushMicrotasksQueue ( ) ;
198+ const waitGetAllBy : Promise < ReactTestInstance [ ] > [ ] = [
199+ waitFor < ReactTestInstance [ ] > ( ( ) => tree . getAllByA11yLabel ( 'label' ) ) ,
200+ waitFor < ReactTestInstance [ ] > ( ( ) => tree . getAllByA11yLabel ( 'label' ) , {
201+ timeout : 10 ,
202+ } ) ,
203+ waitFor < ReactTestInstance [ ] > ( ( ) => tree . getAllByA11yLabel ( 'label' ) , {
204+ timeout : 100 ,
205+ interval : 10 ,
206+ } ) ,
207+ ] ;
254208
255- const waitBy : Promise < ReactTestInstance > = waitFor < ReactTestInstance > ( ( ) =>
256- tree . getByA11yLabel ( 'label' )
257- ) ;
258- const waitByAll : Promise < ReactTestInstance [ ] > = waitFor < ReactTestInstance [ ] > (
259- ( ) => tree . getAllByA11yLabel ( 'label' ) ,
260- { timeout : 1000 , interval : 50 }
261- ) ;
209+ const waitForFlush : Promise < any > = flushMicrotasksQueue ( ) ;
262210
211+ // act API
263212act ( ( ) => {
264213 render ( < TestComponent /> ) ;
265214} ) ;
0 commit comments