From cae754672ee7eacb1cfb041d9ab82911adca736c Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Wed, 4 Jun 2014 12:48:20 -0700 Subject: [PATCH] Add mock request/response classes for testing --- test/support/mock_request.js | 20 ++++++++++++++++++++ test/support/mock_response.js | 16 ++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 test/support/mock_request.js create mode 100644 test/support/mock_response.js diff --git a/test/support/mock_request.js b/test/support/mock_request.js new file mode 100644 index 0000000..8b760ee --- /dev/null +++ b/test/support/mock_request.js @@ -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]; + } +}; diff --git a/test/support/mock_response.js b/test/support/mock_response.js new file mode 100644 index 0000000..a2b12df --- /dev/null +++ b/test/support/mock_response.js @@ -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; +};