Add mock request/response classes for testing

This commit is contained in:
Andrew Stewart 2014-06-04 12:48:20 -07:00
parent 014574a545
commit cae754672e
2 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,20 @@
'use strict';
var sinon = require('sinon'),
spy = sinon.spy,
stub = sinon.stub;
// A mock version of the http.ClientRequest class
var MockRequest = module.exports = function MockRequest(opts) {
if (opts == null) {
opts = {};
}
this.url = "/";
this.headers = {};
for (var opt in opts) {
this[opt] = opts[opt];
}
};

View File

@ -0,0 +1,16 @@
'use strict';
var sinon = require('sinon'),
spy = sinon.spy,
stub = sinon.stub;
// A mock version of http.ServerResponse to be used in tests
var MockResponse = module.exports = function MockResponse() {
this.end = spy();
this.headers = {};
};
MockResponse.prototype.setHeader = function setHeader(name, value) {
this.headers[name] = value;
};