Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/create-matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export function createMatcher (routes: Array<RouteConfig>): Matcher {

if (name) {
const record = nameMap[name]
if (process.env.NODE_ENV !== 'production') {
warn(record, `Route with name '${name}' does not exist`)
}
const paramNames = getRouteRegex(record.path).keys
.filter(key => !key.optional)
.map(key => key.name)
Expand Down
31 changes: 31 additions & 0 deletions test/unit/specs/create-matcher.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*eslint-disable no-undef*/
import { createMatcher } from '../../../src/create-matcher'

const routes = [
{ path: '/', name: 'home', component: { name: 'home' } },
{ path: '/foo', name: 'foo', component: { name: 'foo' } },
]

describe('Creating Matcher', function () {
beforeAll(function () {
spyOn(console, 'warn')
this.match = createMatcher(routes)
})
beforeEach(function () {
console.warn.calls.reset()
process.env.NODE_ENV = 'production'
})

it('in development, has logged a warning if a named route does not exist', function () {
process.env.NODE_ENV = 'development'
expect(() => {
this.match({ name: 'bar' }, routes[0]);
}).toThrow(new TypeError('Cannot read property \'path\' of undefined'));
expect(console.warn).toHaveBeenCalled()
expect(console.warn.calls.argsFor(0)[0]).toMatch('Route with name \'bar\' does not exist');
})
it('in production, it has not logged this warning', function () {
this.match({ name: 'foo' }, routes[0]);
expect(console.warn).not.toHaveBeenCalled()
})
})