From c7d0567da1fce651515051ddbbdc41a657cce2b0 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Sat, 16 Mar 2024 10:11:13 -0700 Subject: [PATCH] test: use retryable assertion for `scrollY` (#26298) --- test/basic.test.ts | 92 +++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 50 deletions(-) diff --git a/test/basic.test.ts b/test/basic.test.ts index e7cd7e15ac..cdff0b331f 100644 --- a/test/basic.test.ts +++ b/test/basic.test.ts @@ -717,61 +717,53 @@ describe('nuxt links', () => { await page.close() }) - it('expect scroll to top on routes with same component', - async () => { - // #22402 - const page = await createPage('/big-page-1', { - viewport: { - width: 1000, - height: 1000 - } - }) - await page.waitForFunction(() => window.useNuxtApp?.()._route.fullPath === '/big-page-1') + it('expect scroll to top on routes with same component', async () => { + // #22402 + const page = await createPage('/big-page-1', { + viewport: { + width: 1000, + height: 1000 + } + }) + await page.waitForFunction(() => window.useNuxtApp?.()._route.fullPath === '/big-page-1') - await page.locator('#big-page-2').scrollIntoViewIfNeeded() - expect(await page.evaluate(() => window.scrollY)).toBeGreaterThan(0) - await page.locator('#big-page-2').click() - await page.waitForFunction(path => window.useNuxtApp?.()._route.fullPath === path, '/big-page-2') - expect(await page.evaluate(() => window.scrollY)).toBe(0) + await page.locator('#big-page-2').scrollIntoViewIfNeeded() + await page.waitForFunction(() => window.scrollY > 0) + await page.locator('#big-page-2').click() + await page.waitForFunction(path => window.useNuxtApp?.()._route.fullPath === path, '/big-page-2') + await page.waitForFunction(() => window.scrollY === 0) - await page.locator('#big-page-1').scrollIntoViewIfNeeded() - expect(await page.evaluate(() => window.scrollY)).toBeGreaterThan(0) - await page.locator('#big-page-1').click() - await page.waitForFunction(path => window.useNuxtApp?.()._route.fullPath === path, '/big-page-1') - expect(await page.evaluate(() => window.scrollY)).toBe(0) - await page.close() - }, - // Flaky behavior when using Webpack - { retry: isWebpack ? 10 : 0 } - ) + await page.locator('#big-page-1').scrollIntoViewIfNeeded() + await page.waitForFunction(() => window.scrollY > 0) + await page.locator('#big-page-1').click() + await page.waitForFunction(path => window.useNuxtApp?.()._route.fullPath === path, '/big-page-1') + await page.waitForFunction(() => window.scrollY === 0) + await page.close() + }) - it('expect scroll to top on nested pages', - async () => { - // #20523 - const page = await createPage('/nested/foo/test', { - viewport: { - width: 1000, - height: 1000 - } - }) - await page.waitForFunction(path => window.useNuxtApp?.()._route.fullPath === path, '/nested/foo/test') + it('expect scroll to top on nested pages', async () => { + // #20523 + const page = await createPage('/nested/foo/test', { + viewport: { + width: 1000, + height: 1000 + } + }) + await page.waitForFunction(path => window.useNuxtApp?.()._route.fullPath === path, '/nested/foo/test') - await page.locator('#user-test').scrollIntoViewIfNeeded() - expect(await page.evaluate(() => window.scrollY)).toBeGreaterThan(0) - await page.locator('#user-test').click() - await page.waitForFunction(path => window.useNuxtApp?.()._route.fullPath === path, '/nested/foo/user-test') - expect(await page.evaluate(() => window.scrollY)).toBe(0) + await page.locator('#user-test').scrollIntoViewIfNeeded() + expect(await page.evaluate(() => window.scrollY)).toBeGreaterThan(0) + await page.locator('#user-test').click() + await page.waitForFunction(path => window.useNuxtApp?.()._route.fullPath === path, '/nested/foo/user-test') + expect(await page.evaluate(() => window.scrollY)).toBe(0) - await page.locator('#test').scrollIntoViewIfNeeded() - expect(await page.evaluate(() => window.scrollY)).toBeGreaterThan(0) - await page.locator('#test').click() - await page.waitForFunction(path => window.useNuxtApp?.()._route.fullPath === path, '/nested/foo/test') - expect(await page.evaluate(() => window.scrollY)).toBe(0) - await page.close() - }, - // Flaky behavior when using Webpack - { retry: isWebpack ? 10 : 0 } - ) + await page.locator('#test').scrollIntoViewIfNeeded() + expect(await page.evaluate(() => window.scrollY)).toBeGreaterThan(0) + await page.locator('#test').click() + await page.waitForFunction(path => window.useNuxtApp?.()._route.fullPath === path, '/nested/foo/test') + expect(await page.evaluate(() => window.scrollY)).toBe(0) + await page.close() + }) }) describe('head tags', () => {