Commit 24832b2
authored
[ui-core] fix race condition resulting in flaky unit test (#33042)
## Summary & Motivation
Attempt to fix flaky test:
```
[2025-12-12T20:05:57Z] FAIL src/assets/__tests__/AssetCatalogTablev2.test.tsx (5.841 s, 520 MB heap size)
[2025-12-12T20:05:57Z] ● AssetCatalogTableV2 › renders
[2025-12-12T20:05:57Z]
[2025-12-12T20:05:57Z] expect(received).toEqual(expected) // deep equality
[2025-12-12T20:05:57Z]
[2025-12-12T20:05:57Z] - Expected - 2
[2025-12-12T20:05:57Z] + Received + 14
[2025-12-12T20:05:57Z]
[2025-12-12T20:05:57Z] - ObjectContaining {
[2025-12-12T20:05:57Z] - "healthDataLoading": false,
[2025-12-12T20:05:57Z] + Object {
[2025-12-12T20:05:57Z] + "allGroups": Array [
[2025-12-12T20:05:57Z] + "Degraded",
[2025-12-12T20:05:57Z] + "Warning",
[2025-12-12T20:05:57Z] + "Healthy",
[2025-12-12T20:05:57Z] + "Unknown",
[2025-12-12T20:05:57Z] + ],
[2025-12-12T20:05:57Z] + "checkedDisplayKeys": Set {},
[2025-12-12T20:05:57Z] + "grouped": Object {},
[2025-12-12T20:05:57Z] + "healthDataLoading": true,
[2025-12-12T20:05:57Z] + "id": "asset-catalog-table-health_status",
[2025-12-12T20:05:57Z] + "loading": false,
[2025-12-12T20:05:57Z] + "onToggleFactory": [Function onToggleFactory],
[2025-12-12T20:05:57Z] + "onToggleGroup": [Function anonymous],
[2025-12-12T20:05:57Z] }
```
- props is a reference to a specific object from a specific render
- When the component re-renders with healthDataLoading: false, it
creates a NEW props object
- The waitFor keeps checking the OLD props object which never changes
- Sometimes passes if health data loads before we capture props
- Sometimes fails if we capture props during loading
Move props retrieval inside the waitFor callback to get fresh props on
each poll:
```
await waitFor(() => {
const calls = (AssetCatalogV2VirtualizedTable as unknown as jest.Mock).mock.calls;
const props = calls[calls.length - 1][0];
expect(props).toEqual(
expect.objectContaining({
healthDataLoading: false,
}),
);
});
```
Now each poll gets the latest mock call → checks current props → passes
when health data is loaded.
## How I Tested These Changes
bk
## Changelog
NOCHANGELOG1 parent 32e0aa2 commit 24832b2
1 file changed
Lines changed: 12 additions & 10 deletions
Lines changed: 12 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
207 | | - | |
208 | | - | |
209 | | - | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
214 | | - | |
215 | | - | |
| 214 | + | |
| 215 | + | |
216 | 216 | | |
| 217 | + | |
| 218 | + | |
217 | 219 | | |
218 | 220 | | |
219 | 221 | | |
| |||
271 | 273 | | |
272 | 274 | | |
273 | 275 | | |
274 | | - | |
275 | | - | |
276 | | - | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
277 | 279 | | |
278 | 280 | | |
279 | 281 | | |
| |||
288 | 290 | | |
289 | 291 | | |
290 | 292 | | |
291 | | - | |
292 | | - | |
| 293 | + | |
| 294 | + | |
293 | 295 | | |
294 | 296 | | |
0 commit comments