mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-18 03:35:17 +00:00
ef7a42649d
nuxt-start and nuxt/legacy are also coming!
78 lines
1.9 KiB
JavaScript
78 lines
1.9 KiB
JavaScript
import { Nuxt, Generator } from '../utils'
|
|
|
|
describe('generator', () => {
|
|
test('initRoutes with routes (fn => array)', async () => {
|
|
const array = ['/1', '/2', '/3', '/4']
|
|
const config = {
|
|
generate: {
|
|
routes: array
|
|
}
|
|
}
|
|
const nuxt = new Nuxt(config)
|
|
const generator = new Generator(nuxt)
|
|
const routes = await generator.initRoutes()
|
|
|
|
expect(routes.length).toBe(array.length)
|
|
routes.map((route, index) => {
|
|
expect(route.route).toBe(array[index])
|
|
})
|
|
})
|
|
|
|
test('initRoutes with routes (fn())', async () => {
|
|
const array = ['/1', '/2', '/3', '/4']
|
|
const config = {
|
|
generate: {
|
|
routes() {
|
|
return array
|
|
}
|
|
}
|
|
}
|
|
const nuxt = new Nuxt(config)
|
|
const generator = new Generator(nuxt)
|
|
const routes = await generator.initRoutes()
|
|
|
|
expect(routes.length).toBe(array.length)
|
|
routes.map((route, index) => {
|
|
expect(route.route).toBe(array[index])
|
|
})
|
|
})
|
|
|
|
test('initRoutes with routes (fn(args))', async () => {
|
|
const config = {
|
|
generate: {
|
|
routes(array) {
|
|
return array
|
|
}
|
|
}
|
|
}
|
|
const nuxt = new Nuxt(config)
|
|
const generator = new Generator(nuxt)
|
|
const array = ['/1', '/2', '/3', '/4']
|
|
const routes = await generator.initRoutes(array)
|
|
|
|
expect(routes.length).toBe(array.length)
|
|
routes.map((route, index) => {
|
|
expect(route.route).toBe(array[index])
|
|
})
|
|
})
|
|
|
|
test('initRoutes with routes (fn(cb, args))', async () => {
|
|
const config = {
|
|
generate: {
|
|
routes(cb, arg1, arg2, arg3, arg4) {
|
|
cb(null, [arg1, arg2, arg3, arg4])
|
|
}
|
|
}
|
|
}
|
|
const nuxt = new Nuxt(config)
|
|
const generator = new Generator(nuxt)
|
|
const array = ['/1', '/2', '/3', '/4']
|
|
const routes = await generator.initRoutes(...array)
|
|
|
|
expect(routes.length).toBe(array.length)
|
|
routes.map((route, index) => {
|
|
expect(route.route).toBe(array[index])
|
|
})
|
|
})
|
|
})
|