Nuxt/test/children.test.js

56 lines
1.8 KiB
JavaScript
Raw Normal View History

2018-03-18 23:41:14 +00:00
import { Nuxt } from '..'
import { loadFixture, getPort } 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-03-18 23:41:14 +00:00
const options = loadFixture('children')
nuxt = new Nuxt(options)
2018-03-18 23:41:14 +00:00
port = await getPort()
await nuxt.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.renderRoute('/parent')
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 () => {
const { html } = await nuxt.renderRoute('/parent/child')
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 () => {
const { html } = await nuxt.renderRoute('/parent')
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 () => {
const { html } = await nuxt.renderRoute('/parent/1')
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 () => {
const { html } = await nuxt.renderRoute('/parent/validate-child')
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 () => {
const { html } = await nuxt.renderRoute('/parent/validate-child?key=12345')
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
test('Closing server and nuxt.js', async () => {
await nuxt.close()
})
2016-12-20 17:05:39 +00:00
})