test: fix & improve ssr warning assertion
This commit is contained in:
parent
80c625dce3
commit
7af089d429
@ -8,11 +8,11 @@ import {
|
|||||||
ref,
|
ref,
|
||||||
defineComponent
|
defineComponent
|
||||||
} from 'vue'
|
} from 'vue'
|
||||||
import { escapeHtml, mockWarn } from '@vue/shared'
|
import { escapeHtml, mockError } from '@vue/shared'
|
||||||
import { renderToString, renderComponent } from '../src/renderToString'
|
import { renderToString, renderComponent } from '../src/renderToString'
|
||||||
import { ssrRenderSlot } from '../src/helpers/ssrRenderSlot'
|
import { ssrRenderSlot } from '../src/helpers/ssrRenderSlot'
|
||||||
|
|
||||||
mockWarn()
|
mockError()
|
||||||
|
|
||||||
describe('ssr: renderToString', () => {
|
describe('ssr: renderToString', () => {
|
||||||
test('should apply app context', async () => {
|
test('should apply app context', async () => {
|
||||||
@ -104,7 +104,7 @@ describe('ssr: renderToString', () => {
|
|||||||
await renderToString(createApp({ template: `<` }))
|
await renderToString(createApp({ template: `<` }))
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
'[Vue warn]: Template compilation error: Unexpected EOF in tag.\n' +
|
'Template compilation error: Unexpected EOF in tag.\n' +
|
||||||
'1 | <\n' +
|
'1 | <\n' +
|
||||||
' | ^'
|
' | ^'
|
||||||
).toHaveBeenWarned()
|
).toHaveBeenWarned()
|
||||||
|
@ -2,17 +2,10 @@ import { createApp, h, Suspense } from 'vue'
|
|||||||
import { renderToString } from '../src/renderToString'
|
import { renderToString } from '../src/renderToString'
|
||||||
import { ssrRenderSuspense } from '../src/helpers/ssrRenderSuspense'
|
import { ssrRenderSuspense } from '../src/helpers/ssrRenderSuspense'
|
||||||
import { ssrRenderComponent } from '../src'
|
import { ssrRenderComponent } from '../src'
|
||||||
|
import { mockError } from '@vue/shared'
|
||||||
|
|
||||||
describe('SSR Suspense', () => {
|
describe('SSR Suspense', () => {
|
||||||
let logError: jest.SpyInstance
|
mockError()
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
logError = jest.spyOn(console, 'error').mockImplementation(() => {})
|
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
logError.mockRestore()
|
|
||||||
})
|
|
||||||
|
|
||||||
const ResolvingAsync = {
|
const ResolvingAsync = {
|
||||||
async setup() {
|
async setup() {
|
||||||
@ -41,7 +34,6 @@ describe('SSR Suspense', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
expect(await renderToString(app)).toBe(`<div>async</div>`)
|
expect(await renderToString(app)).toBe(`<div>async</div>`)
|
||||||
expect(logError).not.toHaveBeenCalled()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('with async component', async () => {
|
test('with async component', async () => {
|
||||||
@ -58,7 +50,6 @@ describe('SSR Suspense', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
expect(await renderToString(app)).toBe(`<div>async</div>`)
|
expect(await renderToString(app)).toBe(`<div>async</div>`)
|
||||||
expect(logError).not.toHaveBeenCalled()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('fallback', async () => {
|
test('fallback', async () => {
|
||||||
@ -78,7 +69,7 @@ describe('SSR Suspense', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
expect(await renderToString(app)).toBe(`<div>fallback</div>`)
|
expect(await renderToString(app)).toBe(`<div>fallback</div>`)
|
||||||
expect(logError).toHaveBeenCalled()
|
expect('Uncaught error in async setup').toHaveBeenWarned()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -94,7 +85,6 @@ describe('SSR Suspense', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expect(await renderToString(createApp(Comp))).toBe(`<div>async</div>`)
|
expect(await renderToString(createApp(Comp))).toBe(`<div>async</div>`)
|
||||||
expect(logError).not.toHaveBeenCalled()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('fallback', async () => {
|
test('fallback', async () => {
|
||||||
@ -108,7 +98,7 @@ describe('SSR Suspense', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expect(await renderToString(createApp(Comp))).toBe(`<div>fallback</div>`)
|
expect(await renderToString(createApp(Comp))).toBe(`<div>fallback</div>`)
|
||||||
expect(logError).toHaveBeenCalled()
|
expect('Uncaught error in async setup').toHaveBeenWarned()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('2 components', async () => {
|
test('2 components', async () => {
|
||||||
@ -124,7 +114,6 @@ describe('SSR Suspense', () => {
|
|||||||
expect(await renderToString(createApp(Comp))).toBe(
|
expect(await renderToString(createApp(Comp))).toBe(
|
||||||
`<div><div>async</div><div>async</div></div>`
|
`<div><div>async</div><div>async</div></div>`
|
||||||
)
|
)
|
||||||
expect(logError).not.toHaveBeenCalled()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('resolving component + rejecting component', async () => {
|
test('resolving component + rejecting component', async () => {
|
||||||
@ -138,7 +127,7 @@ describe('SSR Suspense', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expect(await renderToString(createApp(Comp))).toBe(`<div>fallback</div>`)
|
expect(await renderToString(createApp(Comp))).toBe(`<div>fallback</div>`)
|
||||||
expect(logError).toHaveBeenCalled()
|
expect('Uncaught error in async setup').toHaveBeenWarned()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('failing suspense in passing suspense', async () => {
|
test('failing suspense in passing suspense', async () => {
|
||||||
@ -160,7 +149,7 @@ describe('SSR Suspense', () => {
|
|||||||
expect(await renderToString(createApp(Comp))).toBe(
|
expect(await renderToString(createApp(Comp))).toBe(
|
||||||
`<div><div>async</div><div>fallback 2</div></div>`
|
`<div><div>async</div><div>fallback 2</div></div>`
|
||||||
)
|
)
|
||||||
expect(logError).toHaveBeenCalled()
|
expect('Uncaught error in async setup').toHaveBeenWarned()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('passing suspense in failing suspense', async () => {
|
test('passing suspense in failing suspense', async () => {
|
||||||
@ -182,7 +171,7 @@ describe('SSR Suspense', () => {
|
|||||||
expect(await renderToString(createApp(Comp))).toBe(
|
expect(await renderToString(createApp(Comp))).toBe(
|
||||||
`<div>fallback 1</div>`
|
`<div>fallback 1</div>`
|
||||||
)
|
)
|
||||||
expect(logError).toHaveBeenCalled()
|
expect('Uncaught error in async setup').toHaveBeenWarned()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -8,7 +8,9 @@ declare global {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mockWarn() {
|
export const mockError = () => mockWarn(true)
|
||||||
|
|
||||||
|
export function mockWarn(asError = false) {
|
||||||
expect.extend({
|
expect.extend({
|
||||||
toHaveBeenWarned(received: string) {
|
toHaveBeenWarned(received: string) {
|
||||||
asserted.add(received)
|
asserted.add(received)
|
||||||
@ -79,7 +81,7 @@ export function mockWarn() {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
asserted.clear()
|
asserted.clear()
|
||||||
warn = jest.spyOn(console, 'warn')
|
warn = jest.spyOn(console, asError ? 'error' : 'warn')
|
||||||
warn.mockImplementation(() => {})
|
warn.mockImplementation(() => {})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user