From 0e1eea39de2a8d53add448066462fa6dbe35c924 Mon Sep 17 00:00:00 2001 From: Stas Karpov Date: Fri, 16 Dec 2016 16:57:19 +0300 Subject: [PATCH 1/6] Show warning message if route does exist --- src/create-matcher.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/create-matcher.js b/src/create-matcher.js index a83a05a39..ce9d7bfca 100644 --- a/src/create-matcher.js +++ b/src/create-matcher.js @@ -20,6 +20,7 @@ export function createMatcher (routes: Array): Matcher { if (name) { const record = nameMap[name] + warn(record != null, "Route with name '" + name + "' does not exist"); const paramNames = getRouteRegex(record.path).keys .filter(key => !key.optional) .map(key => key.name) From 3dda246232d9c391eec78ef557e3eb1cad8c77d4 Mon Sep 17 00:00:00 2001 From: Stas Karpov Date: Fri, 16 Dec 2016 17:02:50 +0300 Subject: [PATCH 2/6] Remove semicolon --- src/create-matcher.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/create-matcher.js b/src/create-matcher.js index ce9d7bfca..bb3a69de1 100644 --- a/src/create-matcher.js +++ b/src/create-matcher.js @@ -20,7 +20,7 @@ export function createMatcher (routes: Array): Matcher { if (name) { const record = nameMap[name] - warn(record != null, "Route with name '" + name + "' does not exist"); + warn(record != null, "Route with name '" + name + "' does not exist") const paramNames = getRouteRegex(record.path).keys .filter(key => !key.optional) .map(key => key.name) From 94d69d28b2106795bc435699e904503b18ddc35e Mon Sep 17 00:00:00 2001 From: Stas Karpov Date: Sun, 18 Dec 2016 11:29:43 +0300 Subject: [PATCH 3/6] Add test to warning of not existing route --- src/create-matcher.js | 4 +++- test/unit/specs/create-matcher.spec.js | 31 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 test/unit/specs/create-matcher.spec.js diff --git a/src/create-matcher.js b/src/create-matcher.js index bb3a69de1..0f470c2cf 100644 --- a/src/create-matcher.js +++ b/src/create-matcher.js @@ -20,7 +20,9 @@ export function createMatcher (routes: Array): Matcher { if (name) { const record = nameMap[name] - warn(record != null, "Route with name '" + name + "' does not exist") + if (process.env.NODE_ENV !== 'production') { + warn(record != null, "Route with name '" + name + "' does not exist") + } const paramNames = getRouteRegex(record.path).keys .filter(key => !key.optional) .map(key => key.name) diff --git a/test/unit/specs/create-matcher.spec.js b/test/unit/specs/create-matcher.spec.js new file mode 100644 index 000000000..d13f0925f --- /dev/null +++ b/test/unit/specs/create-matcher.spec.js @@ -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 concering named route does ot 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() + }) +}) From 9afb34593d009de1dc11528f5882218a5babc9f2 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Mon, 19 Dec 2016 11:24:29 +0100 Subject: [PATCH 4/6] Use text interpolation --- src/create-matcher.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/create-matcher.js b/src/create-matcher.js index 0f470c2cf..c6fe22c2e 100644 --- a/src/create-matcher.js +++ b/src/create-matcher.js @@ -21,7 +21,7 @@ export function createMatcher (routes: Array): Matcher { if (name) { const record = nameMap[name] if (process.env.NODE_ENV !== 'production') { - warn(record != null, "Route with name '" + name + "' does not exist") + warn(record , `Route with name '${name}' does not exist`) } const paramNames = getRouteRegex(record.path).keys .filter(key => !key.optional) From f4dcf0d1358ae889c161b00ed7a9e67e342e2dc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20L=C3=BCnborg?= Date: Mon, 19 Dec 2016 11:27:24 +0100 Subject: [PATCH 5/6] fix no-space-before-comma eslint error --- src/create-matcher.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/create-matcher.js b/src/create-matcher.js index c6fe22c2e..d90ed049c 100644 --- a/src/create-matcher.js +++ b/src/create-matcher.js @@ -21,7 +21,7 @@ export function createMatcher (routes: Array): Matcher { if (name) { const record = nameMap[name] if (process.env.NODE_ENV !== 'production') { - warn(record , `Route with name '${name}' does not exist`) + warn(record, `Route with name '${name}' does not exist`) } const paramNames = getRouteRegex(record.path).keys .filter(key => !key.optional) From a434f5bfb8ea236835a7817aeccdaa36f29f465d Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Mon, 19 Dec 2016 11:27:28 +0100 Subject: [PATCH 6/6] Fix typo --- test/unit/specs/create-matcher.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/specs/create-matcher.spec.js b/test/unit/specs/create-matcher.spec.js index d13f0925f..916de850c 100644 --- a/test/unit/specs/create-matcher.spec.js +++ b/test/unit/specs/create-matcher.spec.js @@ -16,7 +16,7 @@ describe('Creating Matcher', function () { process.env.NODE_ENV = 'production' }) - it('in development, has logged a warning concering named route does ot exist', function () { + 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]);