Skip to content

Commit

Permalink
Add a test for the prefixed path generation
Browse files Browse the repository at this point in the history
  • Loading branch information
mquandalle committed Oct 3, 2015
1 parent e030416 commit b21b8c6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion client/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {};
Expand Down
22 changes: 18 additions & 4 deletions test/client/router.core.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,15 +574,14 @@ 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() {} });

setBasePath(simulatedBasePath);
FlowRouter.go('/' + rand);
setTimeout(function() {
test.equal(location.pathname, simulatedBasePath + '/' + rand);
setBasePath(previousBasePath);
resetBasePath();
done();
}, 100);
});
Expand All @@ -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();
}
});
Expand All @@ -604,13 +602,29 @@ 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;
FlowRouter._basePath = path;
FlowRouter.initialize();
}

var defaultBasePath = FlowRouter._basePath;
function resetBasePath() {
setBasePath(defaultBasePath);
}

function bind(obj, method) {
return function() {
obj[method].apply(obj, arguments);
Expand Down

0 comments on commit b21b8c6

Please sign in to comment.