Skip to content

Prevent unnecessary Exception with non-existent links #1387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 16, 2017
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
1 change: 1 addition & 0 deletions src/create-matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export function createMatcher (
if (process.env.NODE_ENV !== 'production') {
warn(record, `Route with name '${name}' does not exist`)
}
if (!record) return _createRoute(null, location)
const paramNames = record.regex.keys
.filter(key => !key.optional)
.map(key => key.name)
Expand Down
14 changes: 7 additions & 7 deletions test/unit/specs/create-matcher.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import { createMatcher } from '../../../src/create-matcher'

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

describe('Creating Matcher', function () {
Expand All @@ -21,15 +21,15 @@ describe('Creating Matcher', function () {

it('in development, has logged a warning if a named route does not exist', function () {
process.env.NODE_ENV = 'development'
expect(() => {
match({ name: 'bar' }, routes[0]);
}).toThrow(new TypeError('Cannot read property \'regex\' of undefined'));
const { name, matched } = match({ name: 'bar' }, routes[0])
expect(matched.length).toBe(0)
expect(name).toBe('bar')
expect(console.warn).toHaveBeenCalled()
expect(console.warn.calls.argsFor(0)[0]).toMatch('Route with name \'bar\' does not exist');
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 () {
match({ name: 'foo' }, routes[0]);
match({ name: 'foo' }, routes[0])
expect(console.warn).not.toHaveBeenCalled()
})
})