1
- import { it , describe , expect , afterEach , vi } from 'vitest' ;
1
+ import { it , describe , expect , afterEach , vi , beforeAll , afterAll } from 'vitest' ;
2
2
import { gray } from 'colorette' ;
3
3
import { range } from 'lodash-es' ;
4
- import { renderHook , cleanup as cleanupMountedReactTrees , act } from '@testing-library/react' ;
4
+ import {
5
+ configure as configureReactTestingLib ,
6
+ renderHook ,
7
+ cleanup as cleanupMountedReactTrees ,
8
+ act ,
9
+ } from '@testing-library/react' ;
5
10
import { useAsyncIterState } from '../../src/index.js' ;
6
11
import { asyncIterToArray } from '../utils/asyncIterToArray.js' ;
7
12
import { asyncIterTake } from '../utils/asyncIterTake.js' ;
8
13
import { asyncIterTakeFirst } from '../utils/asyncIterTakeFirst.js' ;
9
14
import { checkPromiseState } from '../utils/checkPromiseState.js' ;
10
15
import { pipe } from '../utils/pipe.js' ;
11
16
17
+ beforeAll ( ( ) => {
18
+ configureReactTestingLib ( { reactStrictMode : true } ) ;
19
+ } ) ;
20
+
21
+ afterAll ( ( ) => {
22
+ configureReactTestingLib ( { reactStrictMode : false } ) ;
23
+ } ) ;
24
+
12
25
afterEach ( ( ) => {
13
26
cleanupMountedReactTrees ( ) ;
14
27
} ) ;
@@ -165,7 +178,7 @@ describe('`useAsyncIterState` hook', () => {
165
178
'Updating states iteratively with the returned setter *in the functional form* works correctly'
166
179
) ,
167
180
async ( ) => {
168
- const renderFn = vi . fn < ( prevState : number | undefined ) => number > ( ) ;
181
+ const valueUpdateInput = vi . fn < ( prevState : number | undefined ) => number > ( ) ;
169
182
const [ values , setValue ] = renderHook ( ( ) => useAsyncIterState < number > ( ) ) . result . current ;
170
183
171
184
const rounds = 3 ;
@@ -175,12 +188,12 @@ describe('`useAsyncIterState` hook', () => {
175
188
176
189
for ( let i = 0 ; i < rounds ; ++ i ) {
177
190
await act ( ( ) => {
178
- setValue ( renderFn . mockImplementation ( _prev => i ) ) ;
191
+ setValue ( valueUpdateInput . mockImplementation ( _prev => i ) ) ;
179
192
currentValues . push ( values . value . current ) ;
180
193
} ) ;
181
194
}
182
195
183
- expect ( renderFn . mock . calls ) . toStrictEqual ( [ [ undefined ] , [ 0 ] , [ 1 ] ] ) ;
196
+ expect ( valueUpdateInput . mock . calls ) . toStrictEqual ( [ [ undefined ] , [ 0 ] , [ 1 ] ] ) ;
184
197
expect ( currentValues ) . toStrictEqual ( [ undefined , 0 , 1 , 2 ] ) ;
185
198
expect ( await yieldsPromise ) . toStrictEqual ( [ 0 , 1 , 2 ] ) ;
186
199
}
@@ -191,7 +204,7 @@ describe('`useAsyncIterState` hook', () => {
191
204
'Updating states as rapidly as possible with the returned setter *in the functional form* works correctly'
192
205
) ,
193
206
async ( ) => {
194
- const renderFn = vi . fn < ( prevState : number | undefined ) => number > ( ) ;
207
+ const valueUpdateInput = vi . fn < ( prevState : number | undefined ) => number > ( ) ;
195
208
196
209
const [ values , setValue ] = renderHook ( ( ) => useAsyncIterState < number > ( ) ) . result . current ;
197
210
@@ -200,11 +213,12 @@ describe('`useAsyncIterState` hook', () => {
200
213
const currentValues = [ values . value . current ] ;
201
214
202
215
for ( let i = 0 ; i < 3 ; ++ i ) {
203
- setValue ( renderFn . mockImplementation ( _prev => i ) ) ;
216
+ setValue ( valueUpdateInput . mockImplementation ( _prev => i ) ) ;
204
217
currentValues . push ( values . value . current ) ;
218
+ // await undefined;
205
219
}
206
220
207
- expect ( renderFn . mock . calls ) . toStrictEqual ( [ [ undefined ] , [ 0 ] , [ 1 ] ] ) ;
221
+ expect ( valueUpdateInput . mock . calls ) . toStrictEqual ( [ [ undefined ] , [ 0 ] , [ 1 ] ] ) ;
208
222
expect ( currentValues ) . toStrictEqual ( [ undefined , 0 , 1 , 2 ] ) ;
209
223
expect ( await yieldPromise ) . toStrictEqual ( 2 ) ;
210
224
}
0 commit comments