Skip to content

Commit

Permalink
fix(router): unmount
Browse files Browse the repository at this point in the history
  • Loading branch information
hekike committed Nov 18, 2017
1 parent 0b60b18 commit 1c84208
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 32 deletions.
12 changes: 5 additions & 7 deletions lib/router.js
Expand Up @@ -196,22 +196,20 @@ Router.prototype.mount = function mount(opts, handlers) {
* @instance
* @function unmount
* @param {String} name - the route name
* @returns {String} the name of the deleted route.
* @returns {Object|undefined} removed route if found
*/
Router.prototype.unmount = function unmount(name) {
assert.string(name, 'name');

var route = this._mounts[name];

if (!route) {
return;
return undefined;
}

// TODO: revisit
throw new Error('Unmount is not implemented');
// this._findMyWay.off(route.method, route.path);
// delete this._mounts[name];
// return route;
this._findMyWay.off(route.method, route.path);
delete this._mounts[name];
return route;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -98,7 +98,7 @@
"escape-regexp-component": "^1.0.2",
"ewma": "^2.0.1",
"finalhandler": "1.1.0",
"find-my-way": "1.7.1",
"find-my-way": "1.8.0",
"formidable": "^1.1.1",
"http-signature": "^1.2.0",
"lodash": "^4.17.4",
Expand Down
48 changes: 24 additions & 24 deletions test/server.test.js
Expand Up @@ -177,30 +177,30 @@ test('use + get (path only)', function(t) {
});
});

// test('rm', function(t) {
// var route = SERVER.get('/foo/:id', function foosy(req, res, next) {
// next();
// });
//
// SERVER.get('/bar/:id', function barsy(req, res, next) {
// t.ok(req.params);
// t.equal(req.params.id, 'foo');
// res.send();
// next();
// });
//
// t.ok(SERVER.rm(route));
//
// CLIENT.get('/foo/bar', function(err, _, res) {
// t.ok(err);
// t.equal(res.statusCode, 404);
// CLIENT.get('/bar/foo', function(err2, __, res2) {
// t.ifError(err2);
// t.equal(res2.statusCode, 200);
// t.end();
// });
// });
// });
test('rm', function(t) {
var routeName = SERVER.get('/foo/:id', function foosy(req, res, next) {
next();
});

SERVER.get('/bar/:id', function barsy(req, res, next) {
t.ok(req.params);
t.equal(req.params.id, 'foo');
res.send();
next();
});

t.ok(SERVER.rm(routeName));

CLIENT.get('/foo/bar', function(err, _, res) {
t.ok(err);
t.equal(res.statusCode, 404);
CLIENT.get('/bar/foo', function(err2, __, res2) {
t.ifError(err2);
t.equal(res2.statusCode, 200);
t.end();
});
});
});

test('use - throws TypeError on non function as argument', function(t) {
var errMsg = 'handler (function) is required';
Expand Down

0 comments on commit 1c84208

Please sign in to comment.