Add more tests

This commit is contained in:
Sébastien Chopin 2016-12-20 18:26:46 +01:00
parent 7df571f088
commit 0ea0bf8d87
6 changed files with 57 additions and 7 deletions

View File

@ -96,6 +96,7 @@ exports.renderRoute = function (url, context = {}) {
// Function used to do dom checking via jsdom
let jsdom = null
exports.renderAndGetWindow = function renderAndGetWindow (url) {
/* istanbul ignore if */
if (!jsdom) {
try {
jsdom = require('jsdom')

View File

@ -57,6 +57,16 @@ test('/async-data', async t => {
t.true(html.includes('<p>Nuxt.js</p>'))
})
test('/validate should display a 404', async t => {
const { html } = await nuxt.renderRoute('/validate')
t.true(html.includes('This page could not be found'))
})
test('/validate?valid=true', async t => {
const { html } = await nuxt.renderRoute('/validate?valid=true')
t.true(html.includes('<h1>I am valid</h1>'))
})
// Close server and ask nuxt to stop listening to file changes
test.after('Closing server and nuxt.js', t => {
server.close()

View File

@ -0,0 +1,11 @@
<template>
<h1>I am valid</h1>
</template>
<script>
export default {
validate ({ query }) {
return Boolean(query.valid)
}
}
</script>

View File

@ -26,18 +26,35 @@ test('/parent', async t => {
t.true(html.includes('<h1>I am the parent</h1>'))
})
test('/parent with _id.vue', async t => {
// const { html } = await nuxt.renderRoute('/parent')
// t.true(html.includes('<h1>I am the parent</h1>'))
// t.true(html.includes('<h2>I am the child</h2>'))
})
test('/parent/child', async t => {
const { html } = await nuxt.renderRoute('/parent/child')
t.true(html.includes('<h1>I am the parent</h1>'))
t.true(html.includes('<h2>I am the child</h2>'))
})
test('/parent should call _id.vue', async t => {
const { html } = await nuxt.renderRoute('/parent')
t.true(html.includes('<h1>I am the parent</h1>'))
t.true(html.includes('<h2>Id=</h2>'))
})
test('/parent/1', async t => {
const { html } = await nuxt.renderRoute('/parent/1')
t.true(html.includes('<h1>I am the parent</h1>'))
t.true(html.includes('<h2>Id=1</h2>'))
})
test('/parent/validate-child should display 404', async t => {
const { html } = await nuxt.renderRoute('/parent/validate-child')
t.true(html.includes('This page could not be found'))
})
test('/parent/validate-child?key=12345', async t => {
const { html } = await nuxt.renderRoute('/parent/validate-child?key=12345')
t.true(html.includes('<h1>I am the parent</h1>'))
t.true(html.includes('<h2>Child valid</h2>'))
})
// Close server and ask nuxt to stop listening to file changes
test.after('Closing server and nuxt.js', t => {
server.close()

View File

@ -1,3 +1,3 @@
<template>
<h2>I am Id {{ $route.params.id }}</h2>
<h2>Id={{ $route.params.id }}</h2>
</template>

View File

@ -0,0 +1,11 @@
<template>
<h2>Child valid</h2>
</template>
<script>
export default {
validate ({ query }) {
return query.key === '12345'
}
}
</script>