From 67ea10cc75982022490db0c32c761875c74efe9d Mon Sep 17 00:00:00 2001 From: Andrei Zhaleznichenka Date: Wed, 26 Jul 2023 14:59:07 +0200 Subject: [PATCH] chore: Fix flaky oscillating resize test (#1373) --- .../__integ__/resizable-columns-misc.test.ts | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/table/__integ__/resizable-columns-misc.test.ts b/src/table/__integ__/resizable-columns-misc.test.ts index ff0765b427..2910bc1cf2 100644 --- a/src/table/__integ__/resizable-columns-misc.test.ts +++ b/src/table/__integ__/resizable-columns-misc.test.ts @@ -10,7 +10,7 @@ const prepareCoordinate = (num: number) => Math.round(num); declare global { interface Window { - __tableResizes__: ResizeObserverEntry[]; + __tableResizes__: number; } } @@ -50,21 +50,17 @@ class ResizableColumnsPage extends BasePageObject { async installObserver(selector: string) { await this.browser.execute(selector => { - window.__tableResizes__ = []; + window.__tableResizes__ = 0; const target = document.querySelector(selector)!; const observer = new ResizeObserver(entries => { - window.__tableResizes__.push(...entries); + window.__tableResizes__ += entries.length; }); observer.observe(target); }, selector); } - flushObservations() { - return this.browser.execute(() => { - const resizes = window.__tableResizes__; - window.__tableResizes__ = []; - return resizes; - }); + getObservations() { + return this.browser.execute(() => window.__tableResizes__); } } @@ -92,11 +88,11 @@ test( await page.installObserver(wrapper.find('table').toSelector()); await page.click('#shrink-container'); await page.waitForJsTimers(); - // flush observations from the container resize - await expect(page.flushObservations()).resolves.not.toEqual([]); + // expected 1 observation after creating observer and 1 caused by container shrink + await expect(page.getObservations()).resolves.toBe(2); await page.waitForJsTimers(); - // ensure there are no ongoing resizes after we flushed the expected ones above - await expect(page.flushObservations()).resolves.toEqual([]); + // ensure there are no more observations added after the expected 2 + await expect(page.getObservations()).resolves.toBe(2); }) );