Permalink
Browse files

[test] middleware layer

  • Loading branch information...
Swaagie committed Jan 19, 2015
1 parent 668fcc7 commit 534b778ace70aab02707ab3a238ab80a1a710d58
Showing with 34 additions and 2 deletions.
  1. +1 −1 middleware/defaults.js
  2. +32 −0 test/middleware.test.js
  3. +1 −1 test/pipe.test.js
View
@@ -11,6 +11,6 @@ var url = require('url');
*/
module.exports = function defaults(req, res) {
req.uri = req.uri || url.parse(req.url, true);
req.query = req.query || req.uri.query || {};
req.query = req.query || req.uri.query;
req.originalUrl = req.url;
};
View
@@ -0,0 +1,32 @@
describe('Middleware', function () {
'use strict';
var common = require('./common')
, assume = require('assume')
, url = require('url')
, defaults = require('../middleware/defaults');
//
// Request stub
//
function Request(url, method) {
this.url = url || '';
this.method = method || 'GET';
}
describe('.defaults', function () {
it('is a function', function () {
assume(defaults).to.be.a('function');
assume(defaults.length).to.equal(2);
});
it('adds compatibility layer for connect middleware', function () {
var req = new Request('/testpath');
defaults(req);
assume(req).to.have.property('uri', url.parse('/testpath', true));
assume(req).to.have.property('query', url.parse('/testpath', true).query);
assume(req).to.have.property('originalUrl', '/testpath');
});
});
});
View
@@ -25,7 +25,7 @@ describe('Pipe', function () {
//
function Response() {
this.setHeader = this.write = this.end = this.once = function noop() {};
};
}
before(function (done) {
server = http.createServer(function () {

0 comments on commit 534b778

Please sign in to comment.