1- import { it , describe , expect , afterEach , vi } from 'vitest' ;
1+ import { it , describe , expect , afterEach , vi , beforeAll , afterAll } from 'vitest' ;
22import { gray } from 'colorette' ;
33import { 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' ;
510import { useAsyncIterState } from '../../src/index.js' ;
611import { asyncIterToArray } from '../utils/asyncIterToArray.js' ;
712import { asyncIterTake } from '../utils/asyncIterTake.js' ;
813import { asyncIterTakeFirst } from '../utils/asyncIterTakeFirst.js' ;
914import { checkPromiseState } from '../utils/checkPromiseState.js' ;
1015import { pipe } from '../utils/pipe.js' ;
1116
17+ beforeAll ( ( ) => {
18+ configureReactTestingLib ( { reactStrictMode : true } ) ;
19+ } ) ;
20+
21+ afterAll ( ( ) => {
22+ configureReactTestingLib ( { reactStrictMode : false } ) ;
23+ } ) ;
24+
1225afterEach ( ( ) => {
1326 cleanupMountedReactTrees ( ) ;
1427} ) ;
@@ -165,7 +178,7 @@ describe('`useAsyncIterState` hook', () => {
165178 'Updating states iteratively with the returned setter *in the functional form* works correctly'
166179 ) ,
167180 async ( ) => {
168- const renderFn = vi . fn < ( prevState : number | undefined ) => number > ( ) ;
181+ const valueUpdateInput = vi . fn < ( prevState : number | undefined ) => number > ( ) ;
169182 const [ values , setValue ] = renderHook ( ( ) => useAsyncIterState < number > ( ) ) . result . current ;
170183
171184 const rounds = 3 ;
@@ -175,12 +188,12 @@ describe('`useAsyncIterState` hook', () => {
175188
176189 for ( let i = 0 ; i < rounds ; ++ i ) {
177190 await act ( ( ) => {
178- setValue ( renderFn . mockImplementation ( _prev => i ) ) ;
191+ setValue ( valueUpdateInput . mockImplementation ( _prev => i ) ) ;
179192 currentValues . push ( values . value . current ) ;
180193 } ) ;
181194 }
182195
183- expect ( renderFn . mock . calls ) . toStrictEqual ( [ [ undefined ] , [ 0 ] , [ 1 ] ] ) ;
196+ expect ( valueUpdateInput . mock . calls ) . toStrictEqual ( [ [ undefined ] , [ 0 ] , [ 1 ] ] ) ;
184197 expect ( currentValues ) . toStrictEqual ( [ undefined , 0 , 1 , 2 ] ) ;
185198 expect ( await yieldsPromise ) . toStrictEqual ( [ 0 , 1 , 2 ] ) ;
186199 }
@@ -191,7 +204,7 @@ describe('`useAsyncIterState` hook', () => {
191204 'Updating states as rapidly as possible with the returned setter *in the functional form* works correctly'
192205 ) ,
193206 async ( ) => {
194- const renderFn = vi . fn < ( prevState : number | undefined ) => number > ( ) ;
207+ const valueUpdateInput = vi . fn < ( prevState : number | undefined ) => number > ( ) ;
195208
196209 const [ values , setValue ] = renderHook ( ( ) => useAsyncIterState < number > ( ) ) . result . current ;
197210
@@ -200,11 +213,12 @@ describe('`useAsyncIterState` hook', () => {
200213 const currentValues = [ values . value . current ] ;
201214
202215 for ( let i = 0 ; i < 3 ; ++ i ) {
203- setValue ( renderFn . mockImplementation ( _prev => i ) ) ;
216+ setValue ( valueUpdateInput . mockImplementation ( _prev => i ) ) ;
204217 currentValues . push ( values . value . current ) ;
218+ // await undefined;
205219 }
206220
207- expect ( renderFn . mock . calls ) . toStrictEqual ( [ [ undefined ] , [ 0 ] , [ 1 ] ] ) ;
221+ expect ( valueUpdateInput . mock . calls ) . toStrictEqual ( [ [ undefined ] , [ 0 ] , [ 1 ] ] ) ;
208222 expect ( currentValues ) . toStrictEqual ( [ undefined , 0 , 1 , 2 ] ) ;
209223 expect ( await yieldPromise ) . toStrictEqual ( 2 ) ;
210224 }
0 commit comments