Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: use retryable assertion for scrollY #26298

Merged
merged 1 commit into from
Mar 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
102 changes: 47 additions & 55 deletions test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

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-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 }
)

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('#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 }
)
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()
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()
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')

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()
})
})

describe('head tags', () => {
Expand Down