Skip to content

Commit

Permalink
Also add test to ensure page key do work
Browse files Browse the repository at this point in the history
  • Loading branch information
mmis1000 committed Sep 30, 2022
1 parent 92c2ccf commit 28d99ee
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
33 changes: 32 additions & 1 deletion test/basic.test.ts
Expand Up @@ -457,6 +457,37 @@ describe('page key', () => {
}
})

try {
await page.goto(url('/fixed-keyed-child-parent/0'))
await page.waitForLoadState('networkidle')

await page.click('[href="/fixed-keyed-child-parent/1"]')
await page.waitForSelector('#page-1')

// Wait for all pending micro ticks to be cleared,
// so we are not resolved too early when there are repeated page loading
await page.evaluate(() => new Promise(resolve => setTimeout(resolve, 0)))

expect(logs.length).toBe(1)
} finally {
done = true
}
})
it('will cause run of setup if navigation changed page key', async () => {
let done = false
const page = await createPage()
const logs: string[] = []

page.on('console', (msg) => {
const text = msg.text()
if (text.includes('Running Child Setup')) {
if (done) {
throw new Error('Test finished prematurely')
}
logs.push(text)
}
})

try {
await page.goto(url('/keyed-child-parent/0'))
await page.waitForLoadState('networkidle')
Expand All @@ -468,7 +499,7 @@ describe('page key', () => {
// so we are not resolved too early when there are repeated page loading
await page.evaluate(() => new Promise(resolve => setTimeout(resolve, 0)))

expect(logs.length).toBe(1)
expect(logs.length).toBe(2)
} finally {
done = true
}
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/basic/pages/fixed-keyed-child-parent.vue
@@ -0,0 +1,6 @@
<template>
<div>
fixed-keyed-child-parent
<NuxtPage />
</div>
</template>
17 changes: 17 additions & 0 deletions test/fixtures/basic/pages/fixed-keyed-child-parent/[foo].vue
@@ -0,0 +1,17 @@
<template>
<div :id="`page-${route.params.foo}`">
[fixed-keyed-child-parent/{{ route.params.foo }}]
<NuxtLink href="/fixed-keyed-child-parent/1">
To another
</NuxtLink>
</div>
</template>

<script setup>
console.log('Running Child Setup')
const route = useRoute()
definePageMeta({
key: 'keyed'
})
</script>
2 changes: 1 addition & 1 deletion test/fixtures/basic/pages/keyed-child-parent/[foo].vue
Expand Up @@ -12,6 +12,6 @@ console.log('Running Child Setup')
const route = useRoute()
definePageMeta({
key: 'keyed'
key: r => 'keyed-' + r.params.foo
})
</script>

0 comments on commit 28d99ee

Please sign in to comment.