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
|
2023-10-16 21:23:38 +00:00
|
|
|
// const url = (route) => 'http://127.0.0.1:' + port + route
|
2016-12-20 17:05:39 +00:00
|
|
|
|
|
|
|
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)
|
2019-03-08 20:43:23 +00:00
|
|
|
await nuxt.ready()
|
|
|
|
|
2018-03-18 23:41:14 +00:00
|
|
|
port = await getPort()
|
2023-10-16 21:23:38 +00:00
|
|
|
await nuxt.server.listen(port, '127.0.0.1')
|
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-11-08 09:41:24 +00:00
|
|
|
expect(html).toContain('<h1>I am the parent</h1>')
|
2018-03-18 19:31:32 +00:00
|
|
|
})
|
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-11-08 09:41:24 +00:00
|
|
|
expect(html).toContain('<h1>I am the parent</h1>')
|
|
|
|
expect(html).toContain('<h2>I am the child</h2>')
|
2018-03-18 19:31:32 +00:00
|
|
|
})
|
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-11-08 09:41:24 +00:00
|
|
|
expect(html).toContain('<h1>I am the parent</h1>')
|
|
|
|
expect(html).toContain('<h2>Id=</h2>')
|
2018-03-18 19:31:32 +00:00
|
|
|
})
|
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-11-08 09:41:24 +00:00
|
|
|
expect(html).toContain('<h1>I am the parent</h1>')
|
|
|
|
expect(html).toContain('<h2>Id=1</h2>')
|
2018-03-18 19:31:32 +00:00
|
|
|
})
|
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-11-08 09:41:24 +00:00
|
|
|
expect(html).toContain('This page could not be found')
|
2018-03-18 19:31:32 +00:00
|
|
|
})
|
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-11-08 09:41:24 +00:00
|
|
|
expect(html).toContain('<h1>I am the parent</h1>')
|
|
|
|
expect(html).toContain('<h2>Child valid</h2>')
|
2018-03-18 19:31:32 +00:00
|
|
|
})
|
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
|
|
|
})
|