Add children tests

This commit is contained in:
Sébastien Chopin 2016-12-20 18:05:39 +01:00
parent f335c8bd03
commit 7df571f088
4 changed files with 57 additions and 0 deletions

45
test/children.test.js Normal file
View File

@ -0,0 +1,45 @@
import test from 'ava'
import { resolve } from 'path'
const port = 4003
// const url = (route) => 'http://localhost:' + port + route
let nuxt = null
let server = null
// Init nuxt.js and create server listening on localhost:4000
test.before('Init Nuxt.js', t => {
const Nuxt = require('../')
const options = {
rootDir: resolve(__dirname, 'children'),
dev: false
}
nuxt = new Nuxt(options)
return nuxt.build()
.then(function () {
server = new nuxt.Server(nuxt)
server.listen(port, 'localhost')
})
})
test('/parent', async t => {
const { html } = await nuxt.renderRoute('/parent')
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>'))
})
// Close server and ask nuxt to stop listening to file changes
test.after('Closing server and nuxt.js', t => {
server.close()
nuxt.close()
})

View File

@ -0,0 +1,6 @@
<template>
<div>
<h1>I am the parent</h1>
<nuxt-child></nuxt-child>
</div>
</template>

View File

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

View File

@ -0,0 +1,3 @@
<template>
<h2>I am the child</h2>
</template>