test: test for dynamic routes

pull/2010/head
Evan You 2 years ago
parent c5f37188a1
commit 956de3bfa2

@ -38,6 +38,19 @@ const sidebar: DefaultTheme.Config['sidebar'] = {
link: '/multi-sidebar/' link: '/multi-sidebar/'
} }
] ]
},
{
text: 'Dynamic Routes',
items: [
{
text: 'Foo',
link: '/dynamic-routes/foo'
},
{
text: 'Bar',
link: '/dynamic-routes/bar'
}
]
} }
], ],
'/multi-sidebar/': [ '/multi-sidebar/': [

@ -1,4 +1,4 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html // Vitest Snapshot v1
exports[`render correct content > main content 1`] = ` exports[`render correct content > main content 1`] = `
[ [

@ -0,0 +1,8 @@
<script setup>
import { useData } from 'vitepress'
const { page } = useData()
</script>
<!-- @content -->
<pre class="params">{{ page.params }}</pre>

@ -0,0 +1,8 @@
export default {
async paths() {
return [
{ params: { id: 'foo' }, content: `# Foo` },
{ params: { id: 'bar' }, content: `# Bar` }
]
}
}

@ -0,0 +1,11 @@
describe('dynamic routes', () => {
test('render correct content', async () => {
await goto('/dynamic-routes/foo')
expect(await page.textContent('h1')).toMatch('Foo')
expect(await page.textContent('pre.params')).toMatch('"id": "foo"')
await goto('/dynamic-routes/bar')
expect(await page.textContent('h1')).toMatch('Bar')
expect(await page.textContent('pre.params')).toMatch('"id": "bar"')
})
})

@ -13,7 +13,8 @@ describe('test multi sidebar sort root', () => {
'Frontmatter', 'Frontmatter',
'& <Text Literals &> code', '& <Text Literals &> code',
'Static Data', 'Static Data',
'Multi Sidebar Test' 'Multi Sidebar Test',
'Dynamic Routes'
]) ])
}) })
}) })

@ -1,4 +1,4 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html // Vitest Snapshot v1
exports[`static data file support in vite 3 > render correct content 1`] = ` exports[`static data file support in vite 3 > render correct content 1`] = `
[ [

Loading…
Cancel
Save