mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
Add more tests
This commit is contained in:
parent
7df571f088
commit
0ea0bf8d87
@ -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')
|
||||
|
@ -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()
|
||||
|
11
test/basic/pages/validate.vue
Normal file
11
test/basic/pages/validate.vue
Normal file
@ -0,0 +1,11 @@
|
||||
<template>
|
||||
<h1>I am valid</h1>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
validate ({ query }) {
|
||||
return Boolean(query.valid)
|
||||
}
|
||||
}
|
||||
</script>
|
@ -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()
|
||||
|
@ -1,3 +1,3 @@
|
||||
<template>
|
||||
<h2>I am Id {{ $route.params.id }}</h2>
|
||||
<h2>Id={{ $route.params.id }}</h2>
|
||||
</template>
|
||||
|
11
test/children/pages/parent/validate-child.vue
Normal file
11
test/children/pages/parent/validate-child.vue
Normal file
@ -0,0 +1,11 @@
|
||||
<template>
|
||||
<h2>Child valid</h2>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
validate ({ query }) {
|
||||
return query.key === '12345'
|
||||
}
|
||||
}
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user