From b21b8c6e66525e6e9e9c819ce992324d0ce851d0 Mon Sep 17 00:00:00 2001 From: Maxime Quandalle Date: Sat, 3 Oct 2015 15:56:22 +0200 Subject: [PATCH] Add a test for the prefixed path generation --- client/router.js | 2 +- test/client/router.core.spec.js | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/client/router.js b/client/router.js index 4276a87..55cef30 100644 --- a/client/router.js +++ b/client/router.js @@ -141,7 +141,7 @@ Router.prototype.path = function(pathDef, fields, queryParams) { // Prefix the path with the router global prefix if (this._basePath) { - path += this._basePath + "/"; + path += "/" + this._basePath + "/"; } fields = fields || {}; diff --git a/test/client/router.core.spec.js b/test/client/router.core.spec.js index 22ef358..160c911 100644 --- a/test/client/router.core.spec.js +++ b/test/client/router.core.spec.js @@ -574,7 +574,6 @@ Tinytest.addAsync( 'Client - Router - base path - url updated', function(test, done) { var simulatedBasePath = '/flow'; - var previousBasePath = FlowRouter._basePath; var rand = Random.id(); FlowRouter.route('/' + rand, { action: function() {} }); @@ -582,7 +581,7 @@ function(test, done) { FlowRouter.go('/' + rand); setTimeout(function() { test.equal(location.pathname, simulatedBasePath + '/' + rand); - setBasePath(previousBasePath); + resetBasePath(); done(); }, 100); }); @@ -591,11 +590,10 @@ Tinytest.addAsync( 'Client - Router - base path - route action called', function(test, done) { var simulatedBasePath = '/flow'; - var previousBasePath = FlowRouter._basePath; var rand = Random.id(); FlowRouter.route('/' + rand, { action: function() { - setBasePath(previousBasePath); + resetBasePath(); done(); } }); @@ -604,6 +602,17 @@ function(test, done) { FlowRouter.go('/' + rand); }); +Tinytest.add( +'Client - Router - base path - path generation', +function(test, done) { + _.each(['/flow', '/flow/', 'flow/', 'flow'], function(simulatedBasePath) { + var rand = Random.id(); + setBasePath(simulatedBasePath); + test.equal(FlowRouter.path('/' + rand), '/flow/' + rand); + }); + resetBasePath(); +}); + function setBasePath(path) { FlowRouter._initialized = false; @@ -611,6 +620,11 @@ function setBasePath(path) { FlowRouter.initialize(); } +var defaultBasePath = FlowRouter._basePath; +function resetBasePath() { + setBasePath(defaultBasePath); +} + function bind(obj, method) { return function() { obj[method].apply(obj, arguments);