Nuxt/test/basic.fail.generate.test.js
Sébastien Chopin c559740b2f test 100%
2016-12-21 20:51:43 +01:00

62 lines
1.7 KiB
JavaScript

import test from 'ava'
import { resolve } from 'path'
test('Fail to generate without routeParams', t => {
const Nuxt = require('../')
const options = {
rootDir: resolve(__dirname, 'fixtures/basic'),
dev: false
// no generate.routeParams
}
const nuxt = new Nuxt(options)
return new Promise((resolve) => {
var oldExit = process.exit
var oldCE = console.error // eslint-disable-line no-console
var _log = ''
console.error = (s) => { _log += s } // eslint-disable-line no-console
process.exit = (code) => {
process.exit = oldExit
console.error = oldCE // eslint-disable-line no-console
t.is(code, 1)
t.true(_log.includes('Could not generate the dynamic route /users/:id'))
resolve()
}
nuxt.generate()
})
})
test('Fail with routeParams which throw an error', t => {
const Nuxt = require('../')
const options = {
rootDir: resolve(__dirname, 'fixtures/basic'),
dev: false,
generate: {
routeParams: {
'/users/:id': function () {
return new Promise((resolve, reject) => {
reject('Not today!')
})
}
}
}
}
const nuxt = new Nuxt(options)
return new Promise((resolve) => {
var oldExit = process.exit
var oldCE = console.error // eslint-disable-line no-console
var _log = ''
console.error = (s) => { _log += s } // eslint-disable-line no-console
process.exit = (code) => {
process.exit = oldExit
console.error = oldCE // eslint-disable-line no-console
t.is(code, 1)
t.true(_log.includes('Could not resolve routeParams[/users/:id]'))
resolve()
}
nuxt.generate()
.catch((e) => {
t.true(e === 'Not today!')
})
})
})