Add test for custom state

This commit is contained in:
Sebastien Chopin 2017-07-27 16:50:24 +02:00
parent 8e79e7ce42
commit 15400e1828
3 changed files with 21 additions and 1 deletions

View File

@ -101,6 +101,11 @@ test('/redirect -> check redirected source', async t => {
t.true(html.includes('<h1>Index page</h1>'))
})
test.only('/special-state -> check window.__NUXT__.test = true', async t => {
const window = await nuxt.renderAndGetWindow(url('/special-state'))
t.is(window.__NUXT__.test, true)
})
test('/error', async t => {
try {
await nuxt.renderRoute('/error', { req: {}, res: {} })

View File

@ -0,0 +1,15 @@
<template>
<h1>Special state in `window.__NUXT__`</h1>
</template>
<script>
export default {
fetch ({ isServer, beforeNuxtRender }) {
if (isServer) {
beforeNuxtRender(({ nuxtState }) => {
nuxtState.test = true
})
}
}
}
</script>

View File

@ -14,7 +14,7 @@ module.exports = {
transition: 'test',
offline: true,
plugins: [
'~/plugins/test.js', // Use ~ for deprication warning coverage
'~/plugins/test.js',
{ src: '~/plugins/only-client.js', ssr: false }
],
loading: '~/components/loading',