mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
test: Add route.meta test
This commit is contained in:
parent
5edf9c4c95
commit
20b548a175
@ -147,6 +147,13 @@ test('/no-ssr', async t => {
|
||||
t.is(await page.$text('h1'), 'Displayed only on client-side')
|
||||
})
|
||||
|
||||
test('/meta', async t => {
|
||||
await page.nuxt.navigate('/meta', true)
|
||||
|
||||
const state = await page.nuxt.storeState()
|
||||
t.deepEqual(state.meta, [{ works: true }])
|
||||
})
|
||||
|
||||
// Close server and ask nuxt to stop listening to file changes
|
||||
test.after('Closing server and nuxt.js', t => {
|
||||
nuxt.close()
|
||||
|
@ -198,6 +198,12 @@ test('/_nuxt/ should return 404', async t => {
|
||||
t.is(err.statusCode, 404)
|
||||
})
|
||||
|
||||
test('/meta', async t => {
|
||||
const { html } = await nuxt.renderRoute('/meta')
|
||||
|
||||
t.true(html.includes('"meta":[{"works":true}]'))
|
||||
})
|
||||
|
||||
// Close server and ask nuxt to stop listening to file changes
|
||||
test.after('Closing server and nuxt.js', t => {
|
||||
nuxt.close()
|
||||
|
3
test/fixtures/basic/middleware/meta.js
vendored
Normal file
3
test/fixtures/basic/middleware/meta.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
export default ({ store, route, redirect }) => {
|
||||
store.commit('setMeta', route.meta)
|
||||
}
|
12
test/fixtures/basic/pages/meta.vue
vendored
Normal file
12
test/fixtures/basic/pages/meta.vue
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
<template>
|
||||
<pre>{{ $store.state.meta }}</pre>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
middleware: 'meta',
|
||||
meta: {
|
||||
works: true
|
||||
}
|
||||
}
|
||||
</script>
|
6
test/fixtures/basic/store/index.js
vendored
6
test/fixtures/basic/store/index.js
vendored
@ -1,9 +1,13 @@
|
||||
export const state = () => ({
|
||||
counter: 1
|
||||
counter: 1,
|
||||
meta: []
|
||||
})
|
||||
|
||||
export const mutations = {
|
||||
increment(state) {
|
||||
state.counter++
|
||||
},
|
||||
setMeta(state, meta) {
|
||||
state.meta = meta
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,9 @@ export async function page(url) {
|
||||
errorData() {
|
||||
return page.evaluate(($nuxt) => $nuxt.nuxt.err, page.$nuxt)
|
||||
},
|
||||
storeState() {
|
||||
return page.evaluate(($nuxt) => $nuxt.$store.state, page.$nuxt)
|
||||
},
|
||||
waitForNavigation() {
|
||||
return page.waitForFunction('window.$nuxt.$loading.$data.show === false')
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user