Skip to content

Commit a96262e

Browse files
committed
test: exercise measured-width branch in header colgroup stability test
1 parent 02badc3 commit a96262e

1 file changed

Lines changed: 35 additions & 9 deletions

File tree

‎tests/Scroll.spec.jsx‎

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,41 @@ describe('Table.Scroll', () => {
193193
expect(headerTable.querySelectorAll('th.rc-table-cell-scrollbar')).toHaveLength(1);
194194
});
195195

196-
it('keep header colgroup stable between empty and filled data', () => {
197-
const emptyRender = renderScrollTable([]);
198-
const filledRender = renderScrollTable([{ key: 1, a: 'x', b: 'y' }]);
199-
200-
// Loaded data should not change the widths declared in the header colgroup,
201-
// otherwise the columns visually jump when the table gets its first rows.
202-
expect(serializeHeaderCols(emptyRender.container)).toEqual(
203-
serializeHeaderCols(filledRender.container),
204-
);
196+
it('use measured widths and keep header colgroup stable between empty and filled data', () => {
197+
// jsdom does not perform layout, so offsetWidth is always 0 and the measured
198+
// width branch (hasMergedColumnWidth) is never exercised. Give the measure-row
199+
// cells real widths to simulate the browser measurement. The values (120/240)
200+
// intentionally differ from the declared widths (100/200) so the test proves
201+
// the measured widths are used instead of the declared fallback.
202+
const domSpy = spyElementPrototypes(HTMLTableCellElement, {
203+
offsetWidth: {
204+
get(originDescriptor) {
205+
if (this.parentElement?.classList.contains('rc-table-measure-row')) {
206+
return [120, 240][this.cellIndex] ?? 0;
207+
}
208+
return originDescriptor.get();
209+
},
210+
},
211+
});
212+
213+
try {
214+
const emptyRender = renderScrollTable([]);
215+
const filledRender = renderScrollTable([{ key: 1, a: 'x', b: 'y' }]);
216+
217+
// Measured widths + the trailing scrollbar column are reserved in both cases.
218+
// Loaded data should not change the header colgroup, otherwise the columns
219+
// visually jump when the table gets its first rows.
220+
expect(serializeHeaderCols(emptyRender.container)).toEqual([
221+
'width: 120px;',
222+
'width: 240px;',
223+
'width: 15px;',
224+
]);
225+
expect(serializeHeaderCols(filledRender.container)).toEqual(
226+
serializeHeaderCols(emptyRender.container),
227+
);
228+
} finally {
229+
domSpy.mockRestore();
230+
}
205231
});
206232
});
207233
});

0 commit comments

Comments
 (0)