2018-03-27 22:28:17 +00:00
|
|
|
import { loadFixture, getPort, Nuxt } from '../utils'
|
2018-03-16 19:52:17 +00:00
|
|
|
|
2018-03-18 23:41:14 +00:00
|
|
|
let port
|
2016-12-20 17:05:39 +00:00
|
|
|
// const url = (route) => 'http://localhost:' + port + route
|
|
|
|
|
|
|
|
let nuxt = null
|
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
describe('children', () => {
|
|
|
|
beforeAll(async () => {
|
2018-08-17 20:25:23 +00:00
|
|
|
const options = await loadFixture('children')
|
2017-12-17 19:30:26 +00:00
|
|
|
nuxt = new Nuxt(options)
|
2018-03-18 23:41:14 +00:00
|
|
|
port = await getPort()
|
2018-10-30 20:42:53 +00:00
|
|
|
await nuxt.server.listen(port, 'localhost')
|
2018-03-18 23:41:14 +00:00
|
|
|
})
|
2016-12-20 17:05:39 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('/parent', async () => {
|
2018-10-30 20:42:53 +00:00
|
|
|
const { html } = await nuxt.server.renderRoute('/parent')
|
2018-03-18 19:31:32 +00:00
|
|
|
expect(html.includes('<h1>I am the parent</h1>')).toBe(true)
|
|
|
|
})
|
2016-12-20 17:05:39 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('/parent/child', async () => {
|
2018-10-30 20:42:53 +00:00
|
|
|
const { html } = await nuxt.server.renderRoute('/parent/child')
|
2018-03-18 19:31:32 +00:00
|
|
|
expect(html.includes('<h1>I am the parent</h1>')).toBe(true)
|
|
|
|
expect(html.includes('<h2>I am the child</h2>')).toBe(true)
|
|
|
|
})
|
2016-12-20 17:05:39 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('/parent should call _id.vue', async () => {
|
2018-10-30 20:42:53 +00:00
|
|
|
const { html } = await nuxt.server.renderRoute('/parent')
|
2018-03-18 19:31:32 +00:00
|
|
|
expect(html.includes('<h1>I am the parent</h1>')).toBe(true)
|
|
|
|
expect(html.includes('<h2>Id=</h2>')).toBe(true)
|
|
|
|
})
|
2016-12-20 17:26:46 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('/parent/1', async () => {
|
2018-10-30 20:42:53 +00:00
|
|
|
const { html } = await nuxt.server.renderRoute('/parent/1')
|
2018-03-18 19:31:32 +00:00
|
|
|
expect(html.includes('<h1>I am the parent</h1>')).toBe(true)
|
|
|
|
expect(html.includes('<h2>Id=1</h2>')).toBe(true)
|
|
|
|
})
|
2016-12-20 17:26:46 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('/parent/validate-child should display 404', async () => {
|
2018-10-30 20:42:53 +00:00
|
|
|
const { html } = await nuxt.server.renderRoute('/parent/validate-child')
|
2018-03-18 19:31:32 +00:00
|
|
|
expect(html.includes('This page could not be found')).toBe(true)
|
|
|
|
})
|
2016-12-20 17:26:46 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('/parent/validate-child?key=12345', async () => {
|
2018-10-30 20:42:53 +00:00
|
|
|
const { html } = await nuxt.server.renderRoute('/parent/validate-child?key=12345')
|
2018-03-18 19:31:32 +00:00
|
|
|
expect(html.includes('<h1>I am the parent</h1>')).toBe(true)
|
|
|
|
expect(html.includes('<h2>Child valid</h2>')).toBe(true)
|
|
|
|
})
|
2016-12-20 17:26:46 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
// Close server and ask nuxt to stop listening to file changes
|
2018-03-30 09:20:16 +00:00
|
|
|
afterAll(async () => {
|
2018-03-18 19:31:32 +00:00
|
|
|
await nuxt.close()
|
|
|
|
})
|
2016-12-20 17:05:39 +00:00
|
|
|
})
|