1
- import { act , renderHook } from "@testing-library/react" ;
1
+ import { act , configure , renderHook } from "@testing-library/react" ;
2
2
import { newSymbol } from "../__testfixtures__/index.js" ;
3
3
import { useListen } from "./useListen.js" ;
4
4
import { LoadingState } from "./useLoadingValue.js" ;
5
- import { it , expect , beforeEach , describe , vi } from "vitest" ;
5
+ import { it , expect , beforeEach , describe , vi , afterEach } from "vitest" ;
6
6
7
7
const result1 = newSymbol ( "Result 1" ) ;
8
8
const result2 = newSymbol ( "Result 2" ) ;
@@ -25,21 +25,37 @@ beforeEach(() => {
25
25
onChange . mockReturnValue ( onChangeUnsubscribe ) ;
26
26
} ) ;
27
27
28
- describe ( "initial state" , ( ) => {
29
- // reference, initialState, expectedValue, expectedLoading
30
- it . each ( [
31
- [ undefined , result1 , undefined , false ] ,
32
- [ undefined , undefined , undefined , false ] ,
33
- [ undefined , LoadingState , undefined , false ] ,
34
- [ refA1 , result1 , result1 , false ] ,
35
- [ refA1 , undefined , undefined , false ] ,
36
- [ refA1 , LoadingState , undefined , true ] ,
37
- ] ) ( "reference=%s initialState=%s" , ( reference , initialState , expectedValue , expectedLoading ) => {
38
- const { result } = renderHook ( ( ) => useListen ( reference , onChange , isEqual , initialState ) ) ;
39
- expect ( result . current ) . toStrictEqual ( [ expectedValue , expectedLoading , undefined ] ) ;
40
- } ) ;
28
+ afterEach ( ( ) => {
29
+ configure ( { reactStrictMode : false } ) ;
41
30
} ) ;
42
31
32
+ describe . each ( [ { reactStrictMode : true } , { reactStrictMode : false } ] ) (
33
+ `strictMode=$reactStrictMode` ,
34
+ ( { reactStrictMode } ) => {
35
+ beforeEach ( ( ) => {
36
+ configure ( { reactStrictMode } ) ;
37
+ } ) ;
38
+
39
+ describe ( "initial state" , ( ) => {
40
+ it . each `
41
+ reference | initialState | expectedValue | expectedLoading
42
+ ${ undefined } | ${ result1 } | ${ undefined } | ${ false }
43
+ ${ undefined } | ${ undefined } | ${ undefined } | ${ false }
44
+ ${ undefined } | ${ LoadingState } | ${ undefined } | ${ false }
45
+ ${ refA1 } | ${ result1 } | ${ result1 } | ${ false }
46
+ ${ refA1 } | ${ undefined } | ${ undefined } | ${ false }
47
+ ${ refA1 } | ${ LoadingState } | ${ undefined } | ${ true }
48
+ ` (
49
+ "reference=$reference initialState=$initialState" ,
50
+ ( { reference, initialState, expectedValue, expectedLoading } ) => {
51
+ const { result } = renderHook ( ( ) => useListen ( reference , onChange , isEqual , initialState ) ) ;
52
+ expect ( result . current ) . toStrictEqual ( [ expectedValue , expectedLoading , undefined ] ) ;
53
+ } ,
54
+ ) ;
55
+ } ) ;
56
+ } ,
57
+ ) ;
58
+
43
59
describe ( "when changing ref" , ( ) => {
44
60
it ( "should not resubscribe for equal ref" , async ( ) => {
45
61
// first ref
0 commit comments