Skip to content

Commit

Permalink
Updating the last resolved route when a default handler is called kra…
Browse files Browse the repository at this point in the history
  • Loading branch information
Krasimir Tsonev authored and emflores committed Sep 19, 2016
1 parent 8452e94 commit 672c669
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 9 deletions.
9 changes: 5 additions & 4 deletions lib/navigo.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/navigo.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/navigo.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/navigo.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "navigo",
"version": "2.3.0",
"version": "2.3.1",
"description": "A simple vanilla JavaScript router with a fallback for older browsers",
"main": "lib/navigo.js",
"jsnext:main": "src/index.js",
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ Navigo.prototype = {
handler(m.params);
return m;
} else if (this._defaultHandler && (url === '' || url === '/')) {
this._lastRouteResolved = url;
this._defaultHandler();
return true;
} else if (this._notFoundHandler) {
Expand Down
25 changes: 24 additions & 1 deletion test/Navigo.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ describe('Given an instance of Navigo', function () {
expect(action).to.be.equal('save');
done();
};

router.on(/users\/(\d+)\/(\w+)\/?/, handler);
router.resolve('site.com/app/users/42/save');
});
Expand All @@ -118,6 +119,7 @@ describe('Given an instance of Navigo', function () {
describe('and when we use the destroy method', function () {
it('should not be able to resolve a route', function () {
var handler = sinon.spy();

router.on('/users', handler);
router.resolve('site.com/app/users');
router.destroy();
Expand Down Expand Up @@ -245,7 +247,7 @@ describe('Given an instance of Navigo', function () {

expect(handler)
.to.be.calledOnce
.and.to.be.calledWith({ productId: '42' })
.and.to.be.calledWith({ productId: '42' });
});
});
});
Expand All @@ -271,4 +273,25 @@ describe('Given an instance of Navigo', function () {
});
});

describe('Given the issue #41 case', function () {
it('should resolve routes properly', function () {
var taskRoute = sinon.spy();
var defaultRoute = sinon.spy();

router = new Navigo('http://site.com/', true);
router.on('/task/:taskId/', taskRoute);
router.on(defaultRoute);

router.resolve('/task/frontend-1');
router.resolve('/');
router.resolve('/task/frontend-1');

expect(defaultRoute).to.be.calledOnce;
expect(taskRoute).to.be.calledTwice;
expect(taskRoute.firstCall).to.be.calledWith({ taskId: 'frontend-1' });
expect(taskRoute.secondCall).to.be.calledWith({ taskId: 'frontend-1' });

});
});

});

0 comments on commit 672c669

Please sign in to comment.