11import {
2+ act ,
23 act as componentAct ,
34 fireEvent ,
45 render ,
6+ renderHook ,
57 screen ,
68} from "@testing-library/react"
7- import { act , renderHook } from "@testing-library/react"
89import React , { FC , StrictMode , Suspense , useEffect , useState } from "react"
10+ import { renderToPipeableStream } from "react-dom/server"
911import {
1012 defer ,
1113 EMPTY ,
@@ -26,17 +28,16 @@ import {
2628 startWith ,
2729 switchMapTo ,
2830} from "rxjs/operators"
29- import { describe , it , beforeAll , afterAll , expect , vi } from "vitest"
31+ import { afterAll , beforeAll , describe , expect , it , vi } from "vitest"
3032import {
3133 bind ,
3234 sinkSuspense ,
3335 Subscribe ,
3436 SUSPENSE ,
3537 useStateObservable ,
3638} from "../"
37- import { TestErrorBoundary } from "../test-helpers/TestErrorBoundary"
38- import { renderToPipeableStream } from "react-dom/server"
3939import { pipeableStreamToObservable } from "../test-helpers/pipeableStreamToObservable"
40+ import { TestErrorBoundary } from "../test-helpers/TestErrorBoundary"
4041
4142const wait = ( ms : number ) => new Promise ( ( res ) => setTimeout ( res , ms ) )
4243
@@ -93,8 +94,13 @@ describe("connectObservable", () => {
9394
9495 await wait ( 110 )
9596
96- expect ( screen . queryByText ( "Result 1" ) ) . not . toBeNull ( )
97- expect ( screen . queryByText ( "Waiting" ) ) . toBeNull ( )
97+ vi . waitFor (
98+ ( ) => {
99+ expect ( screen . queryByText ( "Result 1" ) ) . not . toBeNull ( )
100+ expect ( screen . queryByText ( "Waiting" ) ) . toBeNull ( )
101+ } ,
102+ { timeout : 2000 } ,
103+ )
98104 sub . unsubscribe ( )
99105 } )
100106
@@ -118,8 +124,13 @@ describe("connectObservable", () => {
118124
119125 await wait ( 110 )
120126
121- expect ( screen . queryByText ( "Result 1" ) ) . not . toBeNull ( )
122- expect ( screen . queryByText ( "Waiting" ) ) . toBeNull ( )
127+ vi . waitFor (
128+ ( ) => {
129+ expect ( screen . queryByText ( "Result 1" ) ) . not . toBeNull ( )
130+ expect ( screen . queryByText ( "Waiting" ) ) . toBeNull ( )
131+ } ,
132+ { timeout : 2000 } ,
133+ )
123134 sub . unsubscribe ( )
124135 } )
125136
@@ -183,9 +194,7 @@ describe("connectObservable", () => {
183194 const [ useNumber ] = bind ( numberStream , 1 )
184195 const [ useString ] = bind ( stringStream , "a" )
185196
186- const BatchComponent : FC < {
187- onUpdate : ( ) => void
188- } > = ( { onUpdate } ) => {
197+ const BatchComponent : FC < { onUpdate : ( ) => void } > = ( { onUpdate } ) => {
189198 const number = useNumber ( )
190199 const string = useString ( )
191200 useEffect ( onUpdate )
@@ -329,8 +338,8 @@ describe("connectObservable", () => {
329338 { value === null
330339 ? "default"
331340 : value instanceof Promise
332- ? "promise"
333- : "wtf?" }
341+ ? "promise"
342+ : "wtf?" }
334343 </ div >
335344 )
336345 }
@@ -387,13 +396,17 @@ describe("connectObservable", () => {
387396
388397 await wait ( 10 )
389398
390- expect ( screen . queryByText ( "Waiting" ) ) . toBeNull ( )
391- expect ( screen . queryByText ( "Result 1" ) ) . not . toBeNull ( )
399+ vi . waitFor ( ( ) => {
400+ expect ( screen . queryByText ( "Waiting" ) ) . toBeNull ( )
401+ expect ( screen . queryByText ( "Result 1" ) ) . not . toBeNull ( )
402+ } )
392403
393404 fireEvent . click ( screen . getByText ( / N e x t V a l / i) )
394405
395- expect ( screen . queryByText ( "Result 2" ) ) . not . toBeNull ( )
396- expect ( screen . queryByText ( "Waiting" ) ) . toBeNull ( )
406+ vi . waitFor ( ( ) => {
407+ expect ( screen . queryByText ( "Result 2" ) ) . not . toBeNull ( )
408+ expect ( screen . queryByText ( "Waiting" ) ) . toBeNull ( )
409+ } )
397410
398411 fireEvent . click ( screen . getByText ( / N e x t K e y / i) )
399412
@@ -405,17 +418,21 @@ describe("connectObservable", () => {
405418
406419 await wait ( 10 )
407420
408- expect ( screen . queryByText ( "Result 1" ) ) . not . toBeNull ( )
409- expect ( screen . queryByText ( "Waiting" ) ) . toBeNull ( )
421+ vi . waitFor ( ( ) => {
422+ expect ( screen . queryByText ( "Result 1" ) ) . not . toBeNull ( )
423+ expect ( screen . queryByText ( "Waiting" ) ) . toBeNull ( )
424+ } )
410425
411426 fireEvent . click ( screen . getByText ( / N e x t V a l / i) )
412427
413- expect ( screen . queryByText ( "Result 2" ) ) . not . toBeNull ( )
414- expect ( screen . queryByText ( "Waiting" ) ) . toBeNull ( )
428+ vi . waitFor ( ( ) => {
429+ expect ( screen . queryByText ( "Result 2" ) ) . not . toBeNull ( )
430+ expect ( screen . queryByText ( "Waiting" ) ) . toBeNull ( )
431+ } )
415432 } )
416433
417434 it ( "allows errors to be caught in error boundaries" , ( ) => {
418- const errStream = new Subject ( )
435+ const errStream = new Subject < any > ( )
419436 const [ useError ] = bind ( errStream , 1 )
420437
421438 const ErrorComponent = ( ) => {
@@ -441,7 +458,7 @@ describe("connectObservable", () => {
441458 } )
442459
443460 it ( "allows sync errors to be caught in error boundaries with suspense, using source$" , ( ) => {
444- const errStream = new Observable ( ( observer ) =>
461+ const errStream = new Observable < any > ( ( observer ) =>
445462 observer . error ( "controlled error" ) ,
446463 )
447464 const [ useError , errStream$ ] = bind ( errStream )
@@ -468,7 +485,7 @@ describe("connectObservable", () => {
468485 } )
469486
470487 it ( "allows sync errors to be caught in error boundaries with suspense, without using source$" , ( ) => {
471- const errStream = new Observable ( ( observer ) =>
488+ const errStream = new Observable < any > ( ( observer ) =>
472489 observer . error ( "controlled error" ) ,
473490 )
474491 const [ useError ] = bind ( errStream )
@@ -495,7 +512,7 @@ describe("connectObservable", () => {
495512 } )
496513
497514 it ( "allows sync errors to be caught in error boundaries when there is a default value" , ( ) => {
498- const errStream = new Observable ( ( observer ) =>
515+ const errStream = new Observable < any > ( ( observer ) =>
499516 observer . error ( "controlled error" ) ,
500517 )
501518 const [ useError , errStream$ ] = bind ( errStream , 0 )
@@ -522,7 +539,7 @@ describe("connectObservable", () => {
522539 } )
523540
524541 it ( "allows async errors to be caught in error boundaries with suspense" , async ( ) => {
525- const errStream = new Subject ( )
542+ const errStream = new Subject < any > ( )
526543 const [ useError , errStream$ ] = bind ( errStream )
527544 const errStream$WithoutErrors = errStream$ . pipe ( catchError ( ( ) => NEVER ) )
528545
@@ -702,7 +719,7 @@ describe("connectObservable", () => {
702719 } )
703720
704721 it ( "should throw an error if the stream completes without emitting while on SUSPENSE" , async ( ) => {
705- const subject = new Subject ( )
722+ const subject = new Subject < any > ( )
706723 const [ useValue , value$ ] = bind ( subject )
707724 const errorCallback = vi . fn ( )
708725
0 commit comments