mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 15:22:39 +00:00
Fix tests
This commit is contained in:
parent
8cdd10274f
commit
3fcfe4e026
@ -1,42 +1,16 @@
|
||||
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 => {
|
||||
test('Fail with routes() 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!')
|
||||
})
|
||||
}
|
||||
routes: function () {
|
||||
return new Promise((resolve, reject) => {
|
||||
reject('Not today!')
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -50,7 +24,7 @@ test('Fail with routeParams which throw an error', t => {
|
||||
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]'))
|
||||
t.true(_log.includes('Could not resolve routes'))
|
||||
resolve()
|
||||
}
|
||||
nuxt.generate()
|
||||
|
12
test/fixtures/basic/nuxt.config.js
vendored
12
test/fixtures/basic/nuxt.config.js
vendored
@ -1,11 +1,9 @@
|
||||
module.exports = {
|
||||
generate: {
|
||||
routeParams: {
|
||||
'/users/:id?': [
|
||||
{ id: 1 },
|
||||
{ id: 2 },
|
||||
{ id: 3 }
|
||||
]
|
||||
}
|
||||
routes: [
|
||||
'/users/1',
|
||||
'/users/2',
|
||||
'/users/3'
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -37,9 +37,9 @@ test('urlJoin', t => {
|
||||
t.is(utils.urlJoin('test', '/about'), 'test/about')
|
||||
})
|
||||
|
||||
test('promisifyRouteParams (array)', t => {
|
||||
test('promisifyRoute (array)', t => {
|
||||
const array = [1]
|
||||
const promise = utils.promisifyRouteParams(array)
|
||||
const promise = utils.promisifyRoute(array)
|
||||
t.is(typeof promise, 'object')
|
||||
return promise
|
||||
.then((res) => {
|
||||
@ -47,12 +47,12 @@ test('promisifyRouteParams (array)', t => {
|
||||
})
|
||||
})
|
||||
|
||||
test('promisifyRouteParams (fn => array)', t => {
|
||||
test('promisifyRoute (fn => array)', t => {
|
||||
const array = [1, 2]
|
||||
const fn = function () {
|
||||
return array
|
||||
}
|
||||
const promise = utils.promisifyRouteParams(fn)
|
||||
const promise = utils.promisifyRoute(fn)
|
||||
t.is(typeof promise, 'object')
|
||||
return promise
|
||||
.then((res) => {
|
||||
@ -60,14 +60,14 @@ test('promisifyRouteParams (fn => array)', t => {
|
||||
})
|
||||
})
|
||||
|
||||
test('promisifyRouteParams (fn => promise)', t => {
|
||||
test('promisifyRoute (fn => promise)', t => {
|
||||
const array = [1, 2, 3]
|
||||
const fn = function () {
|
||||
return new Promise((resolve) => {
|
||||
resolve(array)
|
||||
})
|
||||
}
|
||||
const promise = utils.promisifyRouteParams(fn)
|
||||
const promise = utils.promisifyRoute(fn)
|
||||
t.is(typeof promise, 'object')
|
||||
return promise
|
||||
.then((res) => {
|
||||
@ -75,11 +75,11 @@ test('promisifyRouteParams (fn => promise)', t => {
|
||||
})
|
||||
})
|
||||
|
||||
test('promisifyRouteParams (fn(cb) with error)', t => {
|
||||
test('promisifyRoute (fn(cb) with error)', t => {
|
||||
const fn = function (cb) {
|
||||
cb('Error here')
|
||||
}
|
||||
const promise = utils.promisifyRouteParams(fn)
|
||||
const promise = utils.promisifyRoute(fn)
|
||||
t.is(typeof promise, 'object')
|
||||
return promise
|
||||
.catch((e) => {
|
||||
@ -87,12 +87,12 @@ test('promisifyRouteParams (fn(cb) with error)', t => {
|
||||
})
|
||||
})
|
||||
|
||||
test('promisifyRouteParams (fn(cb) with result)', t => {
|
||||
test('promisifyRoute (fn(cb) with result)', t => {
|
||||
const array = [1, 2, 3, 4]
|
||||
const fn = function (cb) {
|
||||
cb(null, array)
|
||||
}
|
||||
const promise = utils.promisifyRouteParams(fn)
|
||||
const promise = utils.promisifyRoute(fn)
|
||||
t.is(typeof promise, 'object')
|
||||
return promise
|
||||
.then((res) => {
|
||||
|
Loading…
Reference in New Issue
Block a user