mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 15:22:39 +00:00
test: add tests for validate with error
This commit is contained in:
parent
87d303845f
commit
83d9dc4105
8
test/fixtures/basic/pages/validate-async.vue
vendored
8
test/fixtures/basic/pages/validate-async.vue
vendored
@ -5,9 +5,15 @@
|
||||
<script>
|
||||
export default {
|
||||
validate({ query }) {
|
||||
return new Promise((resolve) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
if (query.error) {
|
||||
const err = new Error('Custom Error')
|
||||
err.statusCode = parseInt(query.error) || 500
|
||||
reject(err)
|
||||
} else {
|
||||
resolve(Boolean(query.valid))
|
||||
}
|
||||
}, 500)
|
||||
})
|
||||
}
|
||||
|
6
test/fixtures/basic/pages/validate.vue
vendored
6
test/fixtures/basic/pages/validate.vue
vendored
@ -5,6 +5,12 @@
|
||||
<script>
|
||||
export default {
|
||||
validate({ query }) {
|
||||
if (query.error) {
|
||||
const err = new Error('Custom Error')
|
||||
err.statusCode = parseInt(query.error) || 500
|
||||
throw err
|
||||
}
|
||||
|
||||
return Boolean(query.valid)
|
||||
}
|
||||
}
|
||||
|
@ -111,6 +111,18 @@ describe('basic ssr', () => {
|
||||
expect(html.includes('<h1>I am valid</h1>')).toBe(true)
|
||||
})
|
||||
|
||||
test('/validate?error=403', async () => {
|
||||
const { html, error } = await nuxt.renderRoute('/validate?error=403')
|
||||
expect(error).toMatchObject({ statusCode: 403, message: 'Custom Error' })
|
||||
expect(html.includes('Custom Error')).toBe(true)
|
||||
})
|
||||
|
||||
test('/validate-async?error=503', async () => {
|
||||
const { html, error } = await nuxt.renderRoute('/validate-async?error=503')
|
||||
expect(error).toMatchObject({ statusCode: 503, message: 'Custom Error' })
|
||||
expect(html.includes('Custom Error')).toBe(true)
|
||||
})
|
||||
|
||||
test('/before-enter', async () => {
|
||||
const { html } = await nuxt.renderRoute('/before-enter')
|
||||
expect(html.includes('<h1>Index page</h1>')).toBe(true)
|
||||
|
Loading…
Reference in New Issue
Block a user