mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 09:27:13 +00:00
Add children tests
This commit is contained in:
parent
f335c8bd03
commit
7df571f088
45
test/children.test.js
Normal file
45
test/children.test.js
Normal 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()
|
||||||
|
})
|
6
test/children/pages/parent.vue
Normal file
6
test/children/pages/parent.vue
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<h1>I am the parent</h1>
|
||||||
|
<nuxt-child></nuxt-child>
|
||||||
|
</div>
|
||||||
|
</template>
|
3
test/children/pages/parent/_id.vue
Normal file
3
test/children/pages/parent/_id.vue
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<template>
|
||||||
|
<h2>I am Id {{ $route.params.id }}</h2>
|
||||||
|
</template>
|
3
test/children/pages/parent/child.vue
Normal file
3
test/children/pages/parent/child.vue
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<template>
|
||||||
|
<h2>I am the child</h2>
|
||||||
|
</template>
|
Loading…
Reference in New Issue
Block a user