Nuxt/test/unit/renderer.test.js
Sébastien Chopin ef41e205e6 feat: loading screen (#5251)
[release]
2019-03-20 12:47:53 +03:30

54 lines
1.6 KiB
JavaScript

import consola from 'consola'
import { Nuxt } from '../utils'
const NO_BUILD_MSG = /Use either `nuxt build` or `builder\.build\(\)` or start nuxt in development mode/
const NO_MODERN_BUILD_MSG = /Use either `nuxt build --modern` or `modern` option to build modern files/
describe('renderer', () => {
afterEach(() => {
consola.fatal.mockClear()
})
test('detect no-build (Universal)', async () => {
const nuxt = new Nuxt({
_start: true,
mode: 'universal',
dev: false,
buildDir: '/path/to/404'
})
await nuxt.ready()
await expect(nuxt.renderer.renderer.isReady).toBe(false)
expect(consola.fatal).toHaveBeenCalledWith(expect.objectContaining({
message: expect.stringMatching(NO_BUILD_MSG)
}))
})
test('detect no-build (SPA)', async () => {
const nuxt = new Nuxt({
_start: true,
mode: 'spa',
dev: false,
buildDir: '/path/to/404'
})
await nuxt.ready()
await expect(nuxt.renderer.renderer.isReady).toBe(false)
expect(consola.fatal).toHaveBeenCalledWith(expect.objectContaining({
message: expect.stringMatching(NO_BUILD_MSG)
}))
})
test('detect no-modern-build', async () => {
const nuxt = new Nuxt({
_start: true,
mode: 'universal',
modern: 'client',
dev: false,
buildDir: '/path/to/404'
})
await nuxt.ready()
await expect(nuxt.renderer.renderer.isModernReady).toBe(false)
expect(consola.fatal).toHaveBeenCalledWith(expect.objectContaining({
message: expect.stringMatching(NO_MODERN_BUILD_MSG)
}))
})
})