Nuxt/test/unit/generator.test.js

78 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-03-19 10:06:45 +00:00
import { Nuxt, Generator } from '../../'
2018-03-18 19:31:32 +00:00
describe('generator', () => {
test('initRoutes with routes (fn => array)', async () => {
const array = ['/1', '/2', '/3', '/4']
const config = {
generate: {
routes: array
}
}
2018-03-18 19:31:32 +00:00
const nuxt = new Nuxt(config)
const generator = new Generator(nuxt)
const routes = await generator.initRoutes()
2018-03-18 19:31:32 +00:00
expect(routes.length).toBe(array.length)
routes.map((route, index) => {
expect(route.route).toBe(array[index])
})
})
2018-03-18 19:31:32 +00:00
test('initRoutes with routes (fn())', async () => {
const array = ['/1', '/2', '/3', '/4']
const config = {
generate: {
routes() {
return array
}
}
}
2018-03-18 19:31:32 +00:00
const nuxt = new Nuxt(config)
const generator = new Generator(nuxt)
const routes = await generator.initRoutes()
2018-03-18 19:31:32 +00:00
expect(routes.length).toBe(array.length)
routes.map((route, index) => {
expect(route.route).toBe(array[index])
})
})
2018-03-18 19:31:32 +00:00
test('initRoutes with routes (fn(args))', async () => {
const config = {
generate: {
routes(array) {
return array
}
}
}
2018-03-18 19:31:32 +00:00
const nuxt = new Nuxt(config)
const generator = new Generator(nuxt)
const array = ['/1', '/2', '/3', '/4']
const routes = await generator.initRoutes(array)
2018-03-18 19:31:32 +00:00
expect(routes.length).toBe(array.length)
routes.map((route, index) => {
expect(route.route).toBe(array[index])
})
})
2018-03-18 19:31:32 +00:00
test('initRoutes with routes (fn(cb, args))', async () => {
const config = {
generate: {
routes(cb, arg1, arg2, arg3, arg4) {
cb(null, [arg1, arg2, arg3, arg4])
}
}
}
2018-03-18 19:31:32 +00:00
const nuxt = new Nuxt(config)
const generator = new Generator(nuxt)
const array = ['/1', '/2', '/3', '/4']
const routes = await generator.initRoutes(...array)
2018-03-18 19:31:32 +00:00
expect(routes.length).toBe(array.length)
routes.map((route, index) => {
expect(route.route).toBe(array[index])
})
})
})