Nuxt/test/unit/children.test.js

57 lines
1.7 KiB
JavaScript
Raw Normal View History

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 () => {
const options = await loadFixture('children')
nuxt = new Nuxt(options)
await nuxt.ready()
2018-03-18 23:41:14 +00:00
port = await getPort()
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 () => {
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 () => {
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 () => {
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 () => {
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 () => {
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 () => {
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
})