1- import { expect , jest , test } from "@jest/globals" ;
1+ import { beforeEach , expect , jest , test } from "@jest/globals" ;
22
33import type { HostElement } from "../host-element" ;
44import { ReactWorkTag } from "../react-constants" ;
@@ -71,7 +71,7 @@ test("can access composite parent props", async () => {
7171 expect ( fiber . return ! . memoizedProps ) . toEqual ( { className : "test-class" , onChange : handleChange } ) ;
7272} ) ;
7373
74- test ( "findAll should find all elements that match the predicate" , async ( ) => {
74+ test ( "queryAll should find all elements that match the predicate" , async ( ) => {
7575 const renderer = createRoot ( ) ;
7676 await renderWithAct (
7777 renderer ,
@@ -82,7 +82,7 @@ test("findAll should find all elements that match the predicate", async () => {
8282 </ body > ,
8383 ) ;
8484
85- const elements = renderer . container . findAll ( ( element ) => element . type === "div" ) ;
85+ const elements = renderer . container . queryAll ( ( element ) => element . type === "div" ) ;
8686 expect ( elements ) . toHaveLength ( 2 ) ;
8787 expect ( elements [ 0 ] ) . toMatchInlineSnapshot ( `
8888 <div>
@@ -96,7 +96,7 @@ test("findAll should find all elements that match the predicate", async () => {
9696 ` ) ;
9797} ) ;
9898
99- test ( "findAll should find all elements that match the predicate with matchDeepestOnly option" , async ( ) => {
99+ test ( "queryAll should find all elements that match the predicate with matchDeepestOnly option" , async ( ) => {
100100 const renderer = createRoot ( ) ;
101101 await renderWithAct (
102102 renderer ,
@@ -110,7 +110,7 @@ test("findAll should find all elements that match the predicate with matchDeepes
110110 </ body > ,
111111 ) ;
112112
113- const elements = renderer . container . findAll ( ( element ) => element . type === "div" , {
113+ const elements = renderer . container . queryAll ( ( element ) => element . type === "div" , {
114114 matchDeepestOnly : true ,
115115 } ) ;
116116 expect ( elements ) . toHaveLength ( 2 ) ;
@@ -125,3 +125,45 @@ test("findAll should find all elements that match the predicate with matchDeepes
125125 </div>
126126 ` ) ;
127127} ) ;
128+
129+ test ( "queryAll should not return self by default" , async ( ) => {
130+ const renderer = createRoot ( ) ;
131+ await renderWithAct (
132+ renderer ,
133+ < body className = "yes" >
134+ < div className = "yes" > Hello!</ div >
135+ < span className = "yes" > World!</ span >
136+ < div > Foo!</ div >
137+ </ body > ,
138+ ) ;
139+
140+ const elements = getRootElement ( renderer ) . queryAll (
141+ ( element ) => element . props . className === "yes" ,
142+ ) ;
143+ expect ( elements ) . toHaveLength ( 2 ) ;
144+ expect ( elements [ 0 ] . type ) . toBe ( "div" ) ;
145+ expect ( elements [ 1 ] . type ) . toBe ( "span" ) ;
146+ } ) ;
147+
148+ test ( "queryAll should return self if 'includeSelf' is true" , async ( ) => {
149+ const renderer = createRoot ( ) ;
150+ await renderWithAct (
151+ renderer ,
152+ < body className = "yes" >
153+ < div className = "yes" > Hello!</ div >
154+ < span className = "yes" > World!</ span >
155+ < div > Foo!</ div >
156+ </ body > ,
157+ ) ;
158+
159+ const elements = getRootElement ( renderer ) . queryAll (
160+ ( element ) => element . props . className === "yes" ,
161+ {
162+ includeSelf : true ,
163+ } ,
164+ ) ;
165+ expect ( elements ) . toHaveLength ( 3 ) ;
166+ expect ( elements [ 0 ] . type ) . toBe ( "body" ) ;
167+ expect ( elements [ 1 ] . type ) . toBe ( "div" ) ;
168+ expect ( elements [ 2 ] . type ) . toBe ( "span" ) ;
169+ } ) ;
0 commit comments