11import { Client } from "@gadget-client/related-products-example" ;
22import { diff } from "@n1ru4l/json-patch-plus" ;
3- import { render , renderHook } from "@testing-library/react" ;
3+ import { render , renderHook , waitFor } from "@testing-library/react" ;
44import React from "react" ;
55import { useFindMany } from "../src/useFindMany.js" ;
66import { MockGraphQLWSClientWrapper , mockGraphQLWSClient } from "./testWrappers.js" ;
7- import { sleep } from "./utils.js" ;
87
98describe ( "live queries" , ( ) => {
109 let api : Client ;
@@ -37,9 +36,7 @@ describe("live queries", () => {
3736 revision : 1 ,
3837 } as any ) ;
3938
40- await sleep ( 100 ) ;
41-
42- expect ( result . current [ 0 ] . data ! . length ) . toEqual ( 0 ) ;
39+ await waitFor ( ( ) => expect ( result . current [ 0 ] . data ! . length ) . toEqual ( 0 ) ) ;
4340 expect ( result . current [ 0 ] . fetching ) . toBe ( false ) ;
4441 expect ( result . current [ 0 ] . error ) . toBeFalsy ( ) ;
4542
@@ -61,10 +58,9 @@ describe("live queries", () => {
6158 revision : 2 ,
6259 } as any ) ;
6360
64- await sleep ( 100 ) ;
61+ await waitFor ( ( ) => expect ( result . current [ 0 ] . data ! [ 0 ] . email ) . toEqual ( "[email protected] " ) ) ; 6562
6663 expect ( result . current [ 0 ] . data ! [ 0 ] . id ) . toEqual ( "123" ) ;
67- expect ( result . current [ 0 ] . data ! [ 0 ] . email ) . toEqual ( "[email protected] " ) ; 6864 expect ( result . current [ 0 ] . fetching ) . toBe ( false ) ;
6965 expect ( result . current [ 0 ] . error ) . toBeFalsy ( ) ;
7066 } ) ;
@@ -101,10 +97,9 @@ describe("live queries", () => {
10197 revision : 1 ,
10298 } as any ) ;
10399
104- await sleep ( 100 ) ;
100+ await waitFor ( ( ) => expect ( result . current [ 0 ] . fetching ) . toBe ( false ) ) ;
105101
106102 expect ( result . current [ 0 ] . data ! . length ) . toEqual ( 1 ) ;
107- expect ( result . current [ 0 ] . fetching ) . toBe ( false ) ;
108103 expect ( result . current [ 0 ] . error ) . toBeFalsy ( ) ;
109104
110105 const next = {
@@ -118,9 +113,7 @@ describe("live queries", () => {
118113 revision : 2 ,
119114 } as any ) ;
120115
121- await sleep ( 100 ) ;
122-
123- expect ( result . current [ 0 ] . data ! . length ) . toEqual ( 0 ) ;
116+ await waitFor ( ( ) => expect ( result . current [ 0 ] . data ! . length ) . toEqual ( 0 ) ) ;
124117 expect ( result . current [ 0 ] . fetching ) . toBe ( false ) ;
125118 expect ( result . current [ 0 ] . error ) . toBeFalsy ( ) ;
126119 } ) ;
@@ -185,9 +178,7 @@ describe("live queries", () => {
185178 revision : 1 ,
186179 } as any ) ;
187180
188- await sleep ( 100 ) ;
189-
190- expect ( container ) . toHaveTextContent ( "Users: 2, Products: 1" ) ;
181+ await waitFor ( ( ) => expect ( container ) . toHaveTextContent ( "Users: 2, Products: 1" ) ) ;
191182
192183 products . push ( {
193184 data : {
@@ -198,8 +189,6 @@ describe("live queries", () => {
198189 revision : 1 ,
199190 } as any ) ;
200191
201- await sleep ( 100 ) ;
202-
203- expect ( container ) . toHaveTextContent ( "Users: 2, Products: 0" ) ;
192+ await waitFor ( ( ) => expect ( container ) . toHaveTextContent ( "Users: 2, Products: 0" ) ) ;
204193 } ) ;
205194} ) ;
0 commit comments