|
| 1 | +/*eslint-disable no-undef*/ |
| 2 | +import { createRouteMap } from '../../../src/create-route-map' |
| 3 | + |
| 4 | +const Home = { template: '<div>This is Home</div>' } |
| 5 | +const Foo = { template: '<div>This is Foo</div>' } |
| 6 | +const Bar = { template: '<div>This is Bar <router-view></router-view></div>' } |
| 7 | +const Baz = { template: '<div>This is Baz</div>' } |
| 8 | + |
| 9 | +const routes = [ |
| 10 | + { path: '/', name: 'home', component: Home }, |
| 11 | + { path: '/foo', name: 'foo', component: Foo }, |
| 12 | + { |
| 13 | + path: '/bar', |
| 14 | + name: 'bar', |
| 15 | + component: Bar, |
| 16 | + children: [ |
| 17 | + { |
| 18 | + path: '', |
| 19 | + component: Baz, |
| 20 | + name: 'bar.baz' |
| 21 | + } |
| 22 | + ] |
| 23 | + } |
| 24 | +] |
| 25 | + |
| 26 | +describe('Creating Route Map', function () { |
| 27 | + beforeAll(function () { |
| 28 | + spyOn(console, 'warn') |
| 29 | + this.maps = createRouteMap(routes) |
| 30 | + }) |
| 31 | + beforeEach(function () { |
| 32 | + console.warn.calls.reset() |
| 33 | + process.env.NODE_ENV = 'production' |
| 34 | + }) |
| 35 | + |
| 36 | + it('has a pathMap object for default subroute at /bar/', function () { |
| 37 | + expect(this.maps.pathMap['/bar/']).not.toBeUndefined() |
| 38 | + }) |
| 39 | + |
| 40 | + it('has a nameMap object for default subroute at \'bar.baz\'', function () { |
| 41 | + expect(this.maps.nameMap['bar.baz']).not.toBeUndefined() |
| 42 | + }) |
| 43 | + |
| 44 | + it('in development, has logged a warning concering named route of parent and default subroute', function () { |
| 45 | + process.env.NODE_ENV = 'development' |
| 46 | + this.maps = createRouteMap(routes) |
| 47 | + expect(console.warn).toHaveBeenCalled() |
| 48 | + expect(console.warn.calls.argsFor(0)[0]).toMatch('vue-router] Named Route \'bar\'') |
| 49 | + }) |
| 50 | + it('in production, it has not logged this warning', function () { |
| 51 | + this.maps = createRouteMap(routes) |
| 52 | + expect(console.warn).not.toHaveBeenCalled() |
| 53 | + }) |
| 54 | +}) |
0 commit comments