Nuxt/test/children.test.js

60 lines
1.7 KiB
JavaScript
Raw Permalink Normal View History

2016-12-20 17:05:39 +00:00
import test from 'ava'
import { resolve } from 'path'
2017-06-20 11:44:47 +00:00
import { Nuxt, Builder } from '../index.js'
2017-06-14 18:51:14 +00:00
2017-05-21 19:00:01 +00:00
const port = 4004
2016-12-20 17:05:39 +00:00
// const url = (route) => 'http://localhost:' + port + route
let nuxt = null
// Init nuxt.js and create server listening on localhost:4000
2016-12-20 19:44:42 +00:00
test.before('Init Nuxt.js', async t => {
2016-12-20 17:05:39 +00:00
const options = {
2016-12-20 19:44:42 +00:00
rootDir: resolve(__dirname, 'fixtures/children'),
2017-07-22 19:19:35 +00:00
dev: false
2016-12-20 17:05:39 +00:00
}
nuxt = new Nuxt(options)
2017-06-18 17:33:23 +00:00
await new Builder(nuxt).build()
2017-06-20 11:44:47 +00:00
await nuxt.listen(port, 'localhost')
2016-12-20 17:05:39 +00:00
})
test('/parent', async t => {
const { html } = await nuxt.renderRoute('/parent')
t.true(html.includes('<h1>I am the parent</h1>'))
})
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>'))
})
2016-12-20 17:26:46 +00:00
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>'))
})
2016-12-20 17:05:39 +00:00
// Close server and ask nuxt to stop listening to file changes
test.after('Closing server and nuxt.js', t => {
nuxt.close()
})