mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
Add error tests
This commit is contained in:
parent
0ea0bf8d87
commit
095c8efe56
@ -1,6 +1,6 @@
|
||||
import test from 'ava'
|
||||
import { resolve } from 'path'
|
||||
const port = 4002
|
||||
const port = 4000
|
||||
const url = (route) => 'http://localhost:' + port + route
|
||||
|
||||
let nuxt = null
|
||||
@ -67,6 +67,23 @@ test('/validate?valid=true', async t => {
|
||||
t.true(html.includes('<h1>I am valid</h1>'))
|
||||
})
|
||||
|
||||
test('/redirect', async t => {
|
||||
const { html } = await nuxt.renderRoute('/redirect')
|
||||
t.true(html.includes('<div id="__nuxt"></div>'))
|
||||
})
|
||||
|
||||
test('/redirect -> check redirected source', async t => {
|
||||
const window = await nuxt.renderAndGetWindow(url('/redirect'))
|
||||
const html = window.document.body.innerHTML
|
||||
t.true(html.includes('<h1>Index page</h1>'))
|
||||
})
|
||||
|
||||
test('/error', async t => {
|
||||
const { html, error } = await nuxt.renderRoute('/error')
|
||||
t.true(html.includes('Error mouahahah'))
|
||||
t.true(error.message.includes('Error mouahahah'))
|
||||
})
|
||||
|
||||
// Close server and ask nuxt to stop listening to file changes
|
||||
test.after('Closing server and nuxt.js', t => {
|
||||
server.close()
|
||||
|
11
test/basic/pages/error.vue
Normal file
11
test/basic/pages/error.vue
Normal file
@ -0,0 +1,11 @@
|
||||
<template>
|
||||
<h1>Error page</h1>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data () {
|
||||
throw new Error('Error mouahahah')
|
||||
}
|
||||
}
|
||||
</script>
|
3
test/basic/pages/index.vue
Normal file
3
test/basic/pages/index.vue
Normal file
@ -0,0 +1,3 @@
|
||||
<template>
|
||||
<h1>Index page</h1>
|
||||
</template>
|
11
test/basic/pages/redirect.vue
Normal file
11
test/basic/pages/redirect.vue
Normal file
@ -0,0 +1,11 @@
|
||||
<template>
|
||||
<div></div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
fetch ({ redirect }) {
|
||||
return redirect('/')
|
||||
}
|
||||
}
|
||||
</script>
|
@ -1,6 +1,6 @@
|
||||
import test from 'ava'
|
||||
import { resolve } from 'path'
|
||||
const port = 4003
|
||||
const port = 4001
|
||||
// const url = (route) => 'http://localhost:' + port + route
|
||||
|
||||
let nuxt = null
|
||||
|
53
test/error.test.js
Normal file
53
test/error.test.js
Normal file
@ -0,0 +1,53 @@
|
||||
import test from 'ava'
|
||||
import { resolve } from 'path'
|
||||
const port = 4002
|
||||
const url = (route) => 'http://localhost:' + port + route
|
||||
|
||||
let nuxt = null
|
||||
let server = null
|
||||
|
||||
// Init nuxt.js and create server listening on localhost:4000
|
||||
test.before('Init Nuxt.js', t => {
|
||||
const Nuxt = require('../')
|
||||
const options = {
|
||||
rootDir: resolve(__dirname, 'error'),
|
||||
dev: false
|
||||
}
|
||||
nuxt = new Nuxt(options)
|
||||
return nuxt.build()
|
||||
.then(function () {
|
||||
server = new nuxt.Server(nuxt)
|
||||
server.listen(port, 'localhost')
|
||||
})
|
||||
})
|
||||
|
||||
test('/ should display an error', async t => {
|
||||
try {
|
||||
await nuxt.renderRoute('/')
|
||||
} catch (e) {
|
||||
t.true(e.message.includes('not_defined is not defined'))
|
||||
}
|
||||
})
|
||||
|
||||
test('/404 should display an error too', async t => {
|
||||
try {
|
||||
await nuxt.renderRoute('/404')
|
||||
} catch (e) {
|
||||
t.true(e.message.includes('not_defined is not defined'))
|
||||
}
|
||||
})
|
||||
|
||||
test('/ with renderAndGetWindow()', async t => {
|
||||
try {
|
||||
await nuxt.renderAndGetWindow(url('/'))
|
||||
} catch (e) {
|
||||
t.true(e.message.includes('Could not load the nuxt app'))
|
||||
t.true(e.body.includes('not_defined is not defined'))
|
||||
}
|
||||
})
|
||||
|
||||
// Close server and ask nuxt to stop listening to file changes
|
||||
test.after('Closing server and nuxt.js', t => {
|
||||
server.close()
|
||||
nuxt.close()
|
||||
})
|
10
test/error/pages/index.vue
Normal file
10
test/error/pages/index.vue
Normal file
@ -0,0 +1,10 @@
|
||||
<template>
|
||||
<h1>Error page</h1>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
/* eslint no-undef: 0 */
|
||||
export default {
|
||||
not_defined
|
||||
}
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user