Skip to content

Commit bf0a0cd

Browse files
Copilothotlong
andauthored
fix(fields): await async data load in renderGrid slot test
The test asserted renderGrid was called with populated records immediately, but the component renders initially with empty state before the async fetch resolves. Changed to toHaveBeenLastCalledWith inside waitFor to properly await the data-loaded render. Agent-Logs-Url: https://github.com/objectstack-ai/objectui/sessions/bd086065-c65e-4f73-9b25-4fd3976d67e2 Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 01d4b76 commit bf0a0cd

2 files changed

Lines changed: 36 additions & 23 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- **`@object-ui/fields`**: Fixed flaky `RecordPickerDialog` test that asserted
13+
`renderGrid` slot props before async data fetch had completed. The test now
14+
awaits the final render with populated records before asserting.
15+
1016
### Changed
1117

1218
- **`MetadataProvider` now lazy-loads metadata.** Previously the console

packages/fields/src/record-picker.test.tsx

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,29 +1113,36 @@ describe('RecordPickerDialog — renderGrid slot', () => {
11131113
expect(screen.getByTestId('custom-grid')).toBeInTheDocument();
11141114
});
11151115

1116-
// renderGrid should have been called with grid slot props
1117-
expect(renderGrid).toHaveBeenCalledWith(
1118-
expect.objectContaining({
1119-
columns: expect.arrayContaining([
1120-
expect.objectContaining({ field: 'name' }),
1121-
]),
1122-
records: expect.arrayContaining([
1123-
expect.objectContaining({ id: '1', name: 'Acme Corp' }),
1124-
]),
1125-
loading: false,
1126-
totalCount: 1,
1127-
currentPage: 1,
1128-
pageSize: 10,
1129-
sortField: null,
1130-
sortDirection: 'asc',
1131-
onSort: expect.any(Function),
1132-
onPageChange: expect.any(Function),
1133-
onRowClick: expect.any(Function),
1134-
isSelected: expect.any(Function),
1135-
multiple: false,
1136-
idField: 'id',
1137-
}),
1138-
);
1116+
// Wait for data to load, then check the last renderGrid call has records
1117+
await waitFor(() => {
1118+
expect(renderGrid).toHaveBeenLastCalledWith(
1119+
expect.objectContaining({
1120+
columns: expect.arrayContaining([
1121+
expect.objectContaining({ field: 'name' }),
1122+
]),
1123+
records: expect.arrayContaining([
1124+
expect.objectContaining({ id: '1', name: 'Acme Corp' }),
1125+
]),
1126+
loading: false,
1127+
totalCount: 1,
1128+
}),
1129+
);
1130+
});
1131+
1132+
// Verify all expected props are present in the last call
1133+
const lastCallArgs = renderGrid.mock.calls[renderGrid.mock.calls.length - 1][0];
1134+
expect(lastCallArgs).toMatchObject({
1135+
currentPage: 1,
1136+
pageSize: 10,
1137+
sortField: null,
1138+
sortDirection: 'asc',
1139+
multiple: false,
1140+
idField: 'id',
1141+
});
1142+
expect(lastCallArgs.onSort).toBeTypeOf('function');
1143+
expect(lastCallArgs.onPageChange).toBeTypeOf('function');
1144+
expect(lastCallArgs.onRowClick).toBeTypeOf('function');
1145+
expect(lastCallArgs.isSelected).toBeTypeOf('function');
11391146
});
11401147

11411148
it('hides built-in table when renderGrid is provided', async () => {

0 commit comments

Comments
 (0)