mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-13 17:43:59 +00:00
3f1d634fb7
* Minor consistency enhancements * Arrow parenthesis consistency * Change linting rule * Fix typo * Update .eslintrc.js to only require parens for blocks * Update style according to brace-only suggestion * Remove --fix from lint * Tweak no-loading time (failing test) * Tweak no-loading time (failing test) (2) * Tweak no-loading time (failing test) (3) * Tweak no-loading time (failing test) (4) * Tweak no-loading time (failing test) (5)
60 lines
1.6 KiB
JavaScript
60 lines
1.6 KiB
JavaScript
import consola from 'consola'
|
|
import mockLog from '../utils/mock-log'
|
|
import { loadFixture, getPort, Nuxt } from '../utils'
|
|
|
|
let nuxt = null
|
|
|
|
let port
|
|
const url = route => 'http://localhost:' + port + route
|
|
|
|
const renderRoute = async (_url) => {
|
|
const window = await nuxt.renderAndGetWindow(url(_url))
|
|
const head = window.document.head.innerHTML
|
|
const html = window.document.body.innerHTML
|
|
return { window, head, html }
|
|
}
|
|
|
|
describe('spa', () => {
|
|
mockLog(['log'], consola)
|
|
|
|
beforeAll(async () => {
|
|
const config = loadFixture('spa')
|
|
nuxt = new Nuxt(config)
|
|
port = await getPort()
|
|
await nuxt.listen(port, 'localhost')
|
|
})
|
|
|
|
test('/ (basic spa)', async () => {
|
|
const { html } = await renderRoute('/')
|
|
expect(html).toMatch('Hello SPA!')
|
|
expect(consola.log).not.toHaveBeenCalledWith('created')
|
|
expect(consola.log).toHaveBeenCalledWith('mounted')
|
|
})
|
|
|
|
test('/custom (custom layout)', async () => {
|
|
const { html } = await renderRoute('/custom')
|
|
expect(html).toMatch('Custom layout')
|
|
expect(consola.log).toHaveBeenCalledWith('created')
|
|
expect(consola.log).toHaveBeenCalledWith('mounted')
|
|
})
|
|
|
|
test('/mounted', async () => {
|
|
const { html } = await renderRoute('/mounted')
|
|
expect(html).toMatch('<h1>Test: updated</h1>')
|
|
})
|
|
|
|
test('/_nuxt/ (access publicPath in spa mode)', async () => {
|
|
await expect(renderRoute('/_nuxt/')).rejects.toMatchObject({
|
|
response: {
|
|
statusCode: 404,
|
|
statusMessage: 'ResourceNotFound'
|
|
}
|
|
})
|
|
})
|
|
|
|
// Close server and ask nuxt to stop listening to file changes
|
|
afterAll(async () => {
|
|
await nuxt.close()
|
|
})
|
|
})
|