test: spa test

This commit is contained in:
Clark Du 2018-04-18 23:12:27 +08:00
parent 0583558d77
commit 90419e331b
No known key found for this signature in database
GPG Key ID: D0E5986AF78B86D9

View File

@ -1,3 +1,5 @@
import consola from 'consola'
import mockLog from '../utils/mock-log'
import { loadFixture, getPort, Nuxt } from '../utils' import { loadFixture, getPort, Nuxt } from '../utils'
let nuxt = null let nuxt = null
@ -12,7 +14,9 @@ const renderRoute = async _url => {
return { window, head, html } return { window, head, html }
} }
describe.skip('spa', () => { describe('spa', () => {
mockLog(['log'], consola)
beforeAll(async () => { beforeAll(async () => {
const config = loadFixture('spa') const config = loadFixture('spa')
nuxt = new Nuxt(config) nuxt = new Nuxt(config)
@ -21,44 +25,22 @@ describe.skip('spa', () => {
}) })
test('/ (basic spa)', async () => { test('/ (basic spa)', async () => {
// const logSpy = await interceptLog()
const { html } = await renderRoute('/') const { html } = await renderRoute('/')
expect(html.includes('Hello SPA!')).toBe(true) expect(html).toMatch('Hello SPA!')
// release() expect(consola.log).not.toHaveBeenCalledWith('created')
// expect(logSpy.withArgs('created').notCalled).toBe(true) expect(consola.log).toHaveBeenCalledWith('mounted')
// expect(logSpy.withArgs('mounted').calledOnce).toBe(true)
}) })
test('/custom (custom layout)', async () => { test('/custom (custom layout)', async () => {
// const logSpy = await interceptLog()
const { html } = await renderRoute('/custom') const { html } = await renderRoute('/custom')
expect(html.includes('Custom layout')).toBe(true) expect(html).toMatch('Custom layout')
// release() expect(consola.log).toHaveBeenCalledWith('created')
// expect(logSpy.withArgs('created').calledOnce).toBe(true) expect(consola.log).toHaveBeenCalledWith('mounted')
// expect(logSpy.withArgs('mounted').calledOnce).toBe(true)
})
test('/custom (not default layout)', async () => {
// const logSpy = await interceptLog()
const { head } = await renderRoute('/custom')
expect(head.includes('src="/_nuxt/layouts/default.')).toBe(false)
// release()
// expect(logSpy.withArgs('created').calledOnce).toBe(true)
// expect(logSpy.withArgs('mounted').calledOnce).toBe(true)
})
test('/custom (call mounted and created once)', async () => {
// const logSpy = await interceptLog()
await renderRoute('/custom')
// release()
// expect(logSpy.withArgs('created').calledOnce).toBe(true)
// expect(logSpy.withArgs('mounted').calledOnce).toBe(true)
}) })
test('/mounted', async () => { test('/mounted', async () => {
const { html } = await renderRoute('/mounted') const { html } = await renderRoute('/mounted')
expect(html).toMatch('<h1>Test: updated</h1>')
expect(html.includes('<h1>Test: updated</h1>')).toBe(true)
}) })
test('/_nuxt/ (access publicPath in spa mode)', async () => { test('/_nuxt/ (access publicPath in spa mode)', async () => {