test: Add route.meta test

This commit is contained in:
Atinux 2017-11-02 18:07:33 +01:00
parent 5edf9c4c95
commit 20b548a175
6 changed files with 36 additions and 1 deletions

View File

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

View File

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

View 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
View File

@ -0,0 +1,12 @@
<template>
<pre>{{ $store.state.meta }}</pre>
</template>
<script>
export default {
middleware: 'meta',
meta: {
works: true
}
}
</script>

View File

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

View File

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