-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from omsmith/custom-default-handler
feat(default-handler) allow user to specify a default request handler
- Loading branch information
Showing
3 changed files
with
57 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,46 @@ | ||
/* global describe, it */ | ||
/* global afterEach, beforeEach, describe, it */ | ||
|
||
'use strict'; | ||
|
||
var router = new (require('../'))().listen(), | ||
request = require('supertest')(router._server); | ||
var request = require('supertest'); | ||
|
||
var Router = new require('../'); | ||
|
||
describe('router', function () { | ||
it('should 404 with no routes defined', function (done) { | ||
request | ||
var router; | ||
|
||
beforeEach(function () { | ||
router = new Router().listen(); | ||
}); | ||
|
||
afterEach(function () { | ||
router._server.close(); | ||
}); | ||
|
||
it('should 404 with no routes defined, by default', function (done) { | ||
request(router._server) | ||
.get('/') | ||
.expect(404) | ||
.end(done); | ||
}); | ||
|
||
it('should call specified default handler with no routes defined', function (done) { | ||
var handlerCalled = false; | ||
router.default(function (req, res) { | ||
handlerCalled = true; | ||
|
||
res.statusCode = 200; | ||
res.end(); | ||
}); | ||
|
||
request(router._server) | ||
.get('/') | ||
.expect(200) | ||
.expect(function () { | ||
if (!handlerCalled) { | ||
throw new Error('expected custom handler to be called'); | ||
} | ||
}) | ||
.end(done); | ||
}); | ||
}); |