node-mocks-http
Advanced tools
Comparing version 1.5.5 to 1.5.6
@@ -34,3 +34,3 @@ # Contributing | ||
## <a name="feature"></a> Want a Feature? | ||
Need a new feature no yet available on node-mocks-http? Submit a new feature to our [GitHub Repository][issues]. | ||
Need a new feature no yet available on node-mocks-http? Submit a new feature to our [GitHub Repository][issues]. | ||
@@ -156,6 +156,13 @@ Think you can help us out by implementing the feature yourself? Go for it! Just craft and submit your [Pull Request][pulls]. | ||
```bash | ||
npm test | ||
``` | ||
npm test | ||
Also, please adhere to the ESLint's rules by running the following: | ||
npm install -q gulp | ||
gulp lint | ||
Failures in the linting process may fail our continuous integration builds. | ||
Thanks again for helping out! | ||
## <a name="contact"></a> Contact Us | ||
@@ -162,0 +169,0 @@ [![Gitter chat](https://badges.gitter.im/howardabrams/node-mocks-http.png)](https://gitter.im/howardabrams/node-mocks-http) |
@@ -148,4 +148,4 @@ 'use strict'; | ||
if ((statusCode >= 200 && statusCode < 300) || statusCode === 304) { | ||
return fresh(this.headers, (this.res._headers || {})); | ||
if (statusCode >= 200 && statusCode < 300 || statusCode === 304) { | ||
return fresh(this.headers, this.res._headers || {}); | ||
} | ||
@@ -152,0 +152,0 @@ |
@@ -38,3 +38,3 @@ 'use strict'; | ||
var standardRequestOptions = [ | ||
'method', 'url', 'originalUrl', 'path', 'params', 'session', 'cookies', 'headers', 'body', 'query', 'files' | ||
'method', 'url', 'originalUrl', 'path', 'params', 'session', 'cookies', 'headers', 'body', 'query', 'files' | ||
]; | ||
@@ -64,19 +64,19 @@ | ||
mockRequest.method = (options.method) ? options.method : 'GET'; | ||
mockRequest.method = options.method ? options.method : 'GET'; | ||
mockRequest.url = options.url || options.path || ''; | ||
mockRequest.originalUrl = options.originalUrl || mockRequest.url; | ||
mockRequest.path = options.path || | ||
(( (options.url) ? url.parse(options.url).pathname : '' )); | ||
mockRequest.params = (options.params) ? options.params : {}; | ||
((options.url ? url.parse(options.url).pathname : '')); | ||
mockRequest.params = options.params ? options.params : {}; | ||
if (options.session) { | ||
mockRequest.session = options.session; | ||
} | ||
mockRequest.cookies = (options.cookies) ? options.cookies : {}; | ||
mockRequest.cookies = options.cookies ? options.cookies : {}; | ||
if (options.signedCookies) { | ||
mockRequest.signedCookies = options.signedCookies; | ||
} | ||
mockRequest.headers = (options.headers) ? convertKeysToLowerCase(options.headers) : {}; | ||
mockRequest.body = (options.body) ? options.body : {}; | ||
mockRequest.query = (options.query) ? options.query : {}; | ||
mockRequest.files = (options.files) ? options.files : {}; | ||
mockRequest.headers = options.headers ? convertKeysToLowerCase(options.headers) : {}; | ||
mockRequest.body = options.body ? options.body : {}; | ||
mockRequest.query = options.query ? options.query : {}; | ||
mockRequest.files = options.files ? options.files : {}; | ||
@@ -83,0 +83,0 @@ //parse query string from url to object |
@@ -152,3 +152,3 @@ 'use strict'; | ||
} else if (data.httpCode) { | ||
mockResponse.statusCode = data.statusCode; | ||
mockResponse.statusCode = data.httpCode; | ||
} | ||
@@ -169,5 +169,3 @@ | ||
switch (arguments.length) { | ||
case 1: | ||
if (typeof a === 'number') { | ||
@@ -178,7 +176,5 @@ mockResponse.statusCode = a; | ||
} | ||
break; | ||
case 2: | ||
if (typeof a === 'number') { | ||
@@ -195,7 +191,5 @@ _formatData(b); | ||
} | ||
break; | ||
case 3: | ||
_formatData(a); | ||
@@ -205,3 +199,2 @@ mockResponse._headers = b; | ||
console.warn('WARNING: Called send() with deprecated three parameters'); | ||
break; | ||
@@ -211,3 +204,2 @@ | ||
break; | ||
} | ||
@@ -440,19 +432,19 @@ | ||
/** | ||
* Set header `field` to `val`, or pass | ||
* an object of header fields. | ||
* | ||
* Examples: | ||
* | ||
* res.set('Foo', ['bar', 'baz']); | ||
* res.set('Accept', 'application/json'); | ||
* res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' }); | ||
* | ||
* Aliased as `mockResponse.header()`. | ||
* | ||
* @param {String|Object|Array} field | ||
* @param {String} val | ||
* @return {ServerResponse} for chaining | ||
* @api public | ||
*/ | ||
/** | ||
* Set header `field` to `val`, or pass | ||
* an object of header fields. | ||
* | ||
* Examples: | ||
* | ||
* res.set('Foo', ['bar', 'baz']); | ||
* res.set('Accept', 'application/json'); | ||
* res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' }); | ||
* | ||
* Aliased as `mockResponse.header()`. | ||
* | ||
* @param {String|Object|Array} field | ||
* @param {String} val | ||
* @return {ServerResponse} for chaining | ||
* @api public | ||
*/ | ||
mockResponse.set = mockResponse.header = function header(field, val) { | ||
@@ -466,3 +458,5 @@ if (arguments.length === 2) { | ||
mockResponse.setHeader(field, val); | ||
} else { | ||
} else if (typeof field === 'string') { | ||
return mockResponse.getHeader(field); | ||
} else { // eslint-disable-line | ||
for (var key in field) { | ||
@@ -483,4 +477,4 @@ mockResponse.setHeader(key, field[key]); | ||
return mockResponse._headers[name] || | ||
mockResponse._headers[name.toLowerCase()] || | ||
mockResponse._headers[name.toUpperCase()]; | ||
mockResponse._headers[name.toLowerCase()] || | ||
mockResponse._headers[name.toUpperCase()]; | ||
}; | ||
@@ -527,7 +521,4 @@ | ||
mockResponse.redirect = function(a, b) { | ||
switch (arguments.length) { | ||
case 1: | ||
mockResponse.statusCode = 302; | ||
@@ -538,3 +529,2 @@ _redirectUrl = a; | ||
case 2: | ||
if (typeof a === 'number') { | ||
@@ -544,3 +534,2 @@ mockResponse.statusCode = a; | ||
} | ||
break; | ||
@@ -550,5 +539,3 @@ | ||
break; | ||
} | ||
mockResponse.end(); | ||
@@ -564,7 +551,5 @@ }; | ||
mockResponse.render = function(a, b) { | ||
_renderView = a; | ||
switch (arguments.length) { | ||
case 2: | ||
@@ -576,3 +561,2 @@ _renderData = b; | ||
break; | ||
} | ||
@@ -604,3 +588,3 @@ | ||
'Request object unavailable. Use createMocks or pass in a ' + | ||
'request object in createResponse to use format.' | ||
'request object in createResponse to use format.' | ||
); | ||
@@ -696,3 +680,3 @@ } | ||
mockResponse._isJSON = function() { | ||
return (mockResponse.getHeader('Content-Type') === 'application/json'); | ||
return mockResponse.getHeader('Content-Type') === 'application/json'; | ||
}; | ||
@@ -711,9 +695,6 @@ | ||
mockResponse._isUTF8 = function() { | ||
if (!_encoding) { | ||
return false; | ||
} | ||
return (_encoding === 'utf8'); | ||
return _encoding === 'utf8'; | ||
}; | ||
@@ -734,9 +715,6 @@ | ||
mockResponse._isDataLengthValid = function() { | ||
if (mockResponse.getHeader('Content-Length')) { | ||
return (mockResponse.getHeader('Content-Length').toString() === _data.length.toString()); | ||
return mockResponse.getHeader('Content-Length').toString() === _data.length.toString(); | ||
} | ||
return true; | ||
}; | ||
@@ -743,0 +721,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "Mock 'http' objects for testing Express routing functions", | ||
"version": "1.5.5", | ||
"version": "1.5.6", | ||
"homepage": "https://github.com/howardabrams/node-mocks-http", | ||
@@ -8,0 +8,0 @@ "bugs": { |
@@ -376,3 +376,3 @@ 'use strict'; | ||
it('should conver value to string, when called with called with non-string value', function() { | ||
it('should convert value to string, when called with called with non-string value', function() { | ||
var num = 1; | ||
@@ -395,2 +395,7 @@ var obj = { key: 'value' }; | ||
it('returns the header value when called with only a key', function() { | ||
response.header('x', 'y'); | ||
expect(response.header('x')).to.equal('y'); | ||
}); | ||
it('should set headers, when called with a hash of key/values', function() { | ||
@@ -397,0 +402,0 @@ var headers = { |
Sorry, the diff of this file is not supported yet
138070
2998