@@ -19,12 +19,17 @@ describe('`useAsyncIterState` hook', () => {
19
19
const valuesToSet = [ 'a' , 'b' , 'c' ] ;
20
20
21
21
const collectPromise = pipe ( values , asyncIterTake ( valuesToSet . length ) , asyncIterToArray ) ;
22
+ const currentValues = [ values . value . current ] ;
22
23
23
24
for ( const value of valuesToSet ) {
24
- await act ( ( ) => setValue ( value ) ) ;
25
+ await act ( ( ) => {
26
+ setValue ( value ) ;
27
+ currentValues . push ( values . value . current ) ;
28
+ } ) ;
25
29
}
26
30
27
31
expect ( await collectPromise ) . toStrictEqual ( [ 'a' , 'b' , 'c' ] ) ;
32
+ expect ( currentValues ) . toStrictEqual ( [ undefined , 'a' , 'b' , 'c' ] ) ;
28
33
} ) ;
29
34
30
35
it (
@@ -79,6 +84,7 @@ describe('`useAsyncIterState` hook', () => {
79
84
80
85
const collections = await Promise . all ( [ collectPromise1 , collectPromise2 ] ) ;
81
86
expect ( collections ) . toStrictEqual ( [ [ ] , [ ] ] ) ;
87
+ expect ( values . value . current ) . toStrictEqual ( undefined ) ;
82
88
}
83
89
) ;
84
90
@@ -91,13 +97,18 @@ describe('`useAsyncIterState` hook', () => {
91
97
const [ values , setValue ] = renderedHook . result . current ;
92
98
93
99
const [ collectPromise1 , collectPromise2 ] = range ( 2 ) . map ( ( ) => asyncIterToArray ( values ) ) ;
100
+ const currentValues = [ values . value . current ] ;
94
101
95
- await act ( ( ) => setValue ( 'a' ) ) ;
102
+ await act ( ( ) => {
103
+ setValue ( 'a' ) ;
104
+ currentValues . push ( values . value . current ) ;
105
+ } ) ;
96
106
97
107
renderedHook . unmount ( ) ;
98
108
99
109
const collections = await Promise . all ( [ collectPromise1 , collectPromise2 ] ) ;
100
110
expect ( collections ) . toStrictEqual ( [ [ 'a' ] , [ 'a' ] ] ) ;
111
+ expect ( currentValues ) . toStrictEqual ( [ undefined , 'a' ] ) ;
101
112
}
102
113
) ;
103
114
@@ -113,6 +124,7 @@ describe('`useAsyncIterState` hook', () => {
113
124
114
125
const collections = await Promise . all ( range ( 2 ) . map ( ( ) => asyncIterToArray ( values ) ) ) ;
115
126
expect ( collections ) . toStrictEqual ( [ [ ] , [ ] ] ) ;
127
+ expect ( values . value . current ) . toStrictEqual ( undefined ) ;
116
128
}
117
129
) ;
118
130
@@ -124,16 +136,21 @@ describe('`useAsyncIterState` hook', () => {
124
136
const [ values , setValue ] = renderHook ( ( ) => useAsyncIterState < string > ( ) ) . result . current ;
125
137
126
138
const consumeStacks : string [ ] [ ] = [ ] ;
139
+ const currentValues = [ values . value . current ] ;
127
140
128
141
for ( const [ i , value ] of [ 'a' , 'b' , 'c' ] . entries ( ) ) {
129
142
consumeStacks [ i ] = [ ] ;
130
143
( async ( ) => {
131
144
for await ( const v of values ) consumeStacks [ i ] . push ( v ) ;
132
145
} ) ( ) ;
133
- await act ( ( ) => setValue ( value ) ) ;
146
+ await act ( ( ) => {
147
+ setValue ( value ) ;
148
+ currentValues . push ( values . value . current ) ;
149
+ } ) ;
134
150
}
135
151
136
152
expect ( consumeStacks ) . toStrictEqual ( [ [ 'a' , 'b' , 'c' ] , [ 'b' , 'c' ] , [ 'c' ] ] ) ;
153
+ expect ( currentValues ) . toStrictEqual ( [ undefined , 'a' , 'b' , 'c' ] ) ;
137
154
}
138
155
) ;
139
156
} ) ;
0 commit comments