@@ -79,19 +79,22 @@ describe('fixedCacheKey', () => {
79
79
80
80
getByTestId ( c1 , 'trigger' ) . click ( )
81
81
82
- await waitFor ( ( ) =>
82
+ await waitFor ( ( ) => {
83
83
expect ( getByTestId ( c1 , 'status' ) . textContent ) . toBe ( 'fulfilled' )
84
- )
85
- expect ( getByTestId ( c1 , 'data ' ) . textContent ) . toBe ( 'C1 ' )
86
- expect ( getByTestId ( c2 , 'status ' ) . textContent ) . toBe ( 'fulfilled ' )
87
- expect ( getByTestId ( c2 , 'data' ) . textContent ) . toBe ( 'C1' )
84
+ expect ( getByTestId ( c1 , 'data' ) . textContent ) . toBe ( 'C1' )
85
+ expect ( getByTestId ( c2 , 'status ' ) . textContent ) . toBe ( 'fulfilled ' )
86
+ expect ( getByTestId ( c2 , 'data ' ) . textContent ) . toBe ( 'C1 ' )
87
+ } )
88
88
89
89
// test reset from the other component
90
90
getByTestId ( c2 , 'reset' ) . click ( )
91
- expect ( getByTestId ( c1 , 'status' ) . textContent ) . toBe ( 'uninitialized' )
92
- expect ( getByTestId ( c1 , 'data' ) . textContent ) . toBe ( '' )
93
- expect ( getByTestId ( c2 , 'status' ) . textContent ) . toBe ( 'uninitialized' )
94
- expect ( getByTestId ( c2 , 'data' ) . textContent ) . toBe ( '' )
91
+
92
+ await waitFor ( ( ) => {
93
+ expect ( getByTestId ( c1 , 'status' ) . textContent ) . toBe ( 'uninitialized' )
94
+ expect ( getByTestId ( c1 , 'data' ) . textContent ) . toBe ( '' )
95
+ expect ( getByTestId ( c2 , 'status' ) . textContent ) . toBe ( 'uninitialized' )
96
+ expect ( getByTestId ( c2 , 'data' ) . textContent ) . toBe ( '' )
97
+ } )
95
98
} )
96
99
97
100
test ( 'resetting from the component that triggered the mutation resets for each shared result' , async ( ) => {
@@ -140,31 +143,35 @@ describe('fixedCacheKey', () => {
140
143
)
141
144
142
145
// the components with the first cache key should be unaffected
143
- expect ( getByTestId ( c1 , 'data' ) . textContent ) . toBe ( 'C1' )
144
- expect ( getByTestId ( c2 , 'status' ) . textContent ) . toBe ( 'fulfilled' )
145
- expect ( getByTestId ( c2 , 'data' ) . textContent ) . toBe ( 'C1' )
146
- expect ( getByTestId ( c2 , 'status' ) . textContent ) . toBe ( 'fulfilled' )
147
-
148
- // the component with the second cache key should be affected
149
- expect ( getByTestId ( c3 , 'data' ) . textContent ) . toBe ( 'C3' )
150
- expect ( getByTestId ( c3 , 'status' ) . textContent ) . toBe ( 'fulfilled' )
151
- expect ( getByTestId ( c4 , 'data' ) . textContent ) . toBe ( 'C3' )
152
- expect ( getByTestId ( c4 , 'status' ) . textContent ) . toBe ( 'fulfilled' )
146
+ await waitFor ( ( ) => {
147
+ expect ( getByTestId ( c1 , 'data' ) . textContent ) . toBe ( 'C1' )
148
+ expect ( getByTestId ( c2 , 'status' ) . textContent ) . toBe ( 'fulfilled' )
149
+ expect ( getByTestId ( c2 , 'data' ) . textContent ) . toBe ( 'C1' )
150
+ expect ( getByTestId ( c2 , 'status' ) . textContent ) . toBe ( 'fulfilled' )
151
+
152
+ // the component with the second cache key should be affected
153
+ expect ( getByTestId ( c3 , 'data' ) . textContent ) . toBe ( 'C3' )
154
+ expect ( getByTestId ( c3 , 'status' ) . textContent ) . toBe ( 'fulfilled' )
155
+ expect ( getByTestId ( c4 , 'data' ) . textContent ) . toBe ( 'C3' )
156
+ expect ( getByTestId ( c4 , 'status' ) . textContent ) . toBe ( 'fulfilled' )
157
+ } )
153
158
154
159
// test reset from the component that triggered the mutation for the first cache key
155
160
getByTestId ( c1 , 'reset' ) . click ( )
156
161
157
- // the components with the first cache key should be affected
158
- expect ( getByTestId ( c1 , 'data' ) . textContent ) . toBe ( '' )
159
- expect ( getByTestId ( c1 , 'status' ) . textContent ) . toBe ( 'uninitialized' )
160
- expect ( getByTestId ( c2 , 'data' ) . textContent ) . toBe ( '' )
161
- expect ( getByTestId ( c2 , 'status' ) . textContent ) . toBe ( 'uninitialized' )
162
+ await waitFor ( ( ) => {
163
+ // the components with the first cache key should be affected
164
+ expect ( getByTestId ( c1 , 'data' ) . textContent ) . toBe ( '' )
165
+ expect ( getByTestId ( c1 , 'status' ) . textContent ) . toBe ( 'uninitialized' )
166
+ expect ( getByTestId ( c2 , 'data' ) . textContent ) . toBe ( '' )
167
+ expect ( getByTestId ( c2 , 'status' ) . textContent ) . toBe ( 'uninitialized' )
162
168
163
- // the components with the second cache key should be unaffected
164
- expect ( getByTestId ( c3 , 'data' ) . textContent ) . toBe ( 'C3' )
165
- expect ( getByTestId ( c3 , 'status' ) . textContent ) . toBe ( 'fulfilled' )
166
- expect ( getByTestId ( c4 , 'data' ) . textContent ) . toBe ( 'C3' )
167
- expect ( getByTestId ( c4 , 'status' ) . textContent ) . toBe ( 'fulfilled' )
169
+ // the components with the second cache key should be unaffected
170
+ expect ( getByTestId ( c3 , 'data' ) . textContent ) . toBe ( 'C3' )
171
+ expect ( getByTestId ( c3 , 'status' ) . textContent ) . toBe ( 'fulfilled' )
172
+ expect ( getByTestId ( c4 , 'data' ) . textContent ) . toBe ( 'C3' )
173
+ expect ( getByTestId ( c4 , 'status' ) . textContent ) . toBe ( 'fulfilled' )
174
+ } )
168
175
} )
169
176
170
177
test ( 'two mutations with different `fixedCacheKey` do not influence each other' , async ( ) => {
@@ -236,7 +243,10 @@ describe('fixedCacheKey', () => {
236
243
} )
237
244
238
245
test ( 'a component without `fixedCacheKey` has `originalArgs`' , async ( ) => {
239
- render ( < Component name = "C1" /> , { wrapper : storeRef . wrapper } )
246
+ render ( < Component name = "C1" /> , {
247
+ wrapper : storeRef . wrapper ,
248
+ legacyRoot : true ,
249
+ } )
240
250
let c1 = screen . getByTestId ( 'C1' )
241
251
expect ( getByTestId ( c1 , 'status' ) . textContent ) . toBe ( 'uninitialized' )
242
252
expect ( getByTestId ( c1 , 'originalArgs' ) . textContent ) . toBe ( 'undefined' )
@@ -272,7 +282,7 @@ describe('fixedCacheKey', () => {
272
282
< Component name = "C1" fixedCacheKey = "test" value = { p1 } />
273
283
< Component name = "C2" fixedCacheKey = "test" value = { p2 } />
274
284
</ > ,
275
- { wrapper : storeRef . wrapper }
285
+ { wrapper : storeRef . wrapper , legacyRoot : true }
276
286
)
277
287
const c1 = screen . getByTestId ( 'C1' )
278
288
const c2 = screen . getByTestId ( 'C2' )
0 commit comments