[Pkg-javascript-commits] [node-mocks-http] 265/296: Make mockRequest.param work more like express
Thorsten Alteholz
alteholz at moszumanska.debian.org
Mon Feb 8 18:13:43 UTC 2016
This is an automated email from the git hooks/post-receive script.
alteholz pushed a commit to branch master
in repository node-mocks-http.
commit ce9c4da62d4f78671e585f9f8f0cad0b5e1afc83
Author: David Gileadi <david.gileadi at agilex.com>
Date: Thu Sep 24 12:07:58 2015 -0700
Make mockRequest.param work more like express
1. Use a defaultValue param when provided
2. Return undefined when not found, instead of null
---
lib/mockRequest.js | 4 ++--
test/lib/mockRequest.spec.js | 12 ++++++++++++
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/lib/mockRequest.js b/lib/mockRequest.js
index 65a214e..85954f2 100644
--- a/lib/mockRequest.js
+++ b/lib/mockRequest.js
@@ -150,7 +150,7 @@ function createRequest(options) {
* - req.body
* - req.query
*/
- mockRequest.param = function(parameterName) {
+ mockRequest.param = function(parameterName, defaultValue) {
if (mockRequest.params[parameterName]) {
return mockRequest.params[parameterName];
} else if (mockRequest.body[parameterName]) {
@@ -158,7 +158,7 @@ function createRequest(options) {
} else if (mockRequest.query[parameterName]) {
return mockRequest.query[parameterName];
}
- return null;
+ return defaultValue;
};
/**
diff --git a/test/lib/mockRequest.spec.js b/test/lib/mockRequest.spec.js
index 1f2f899..f696ecc 100644
--- a/test/lib/mockRequest.spec.js
+++ b/test/lib/mockRequest.spec.js
@@ -383,6 +383,18 @@ describe('mockRequest', function() {
expect(request.header('key')).to.not.exist;
});
+ it('should return defaultValue, when not found in params/body/query', function() {
+ request = mockRequest.createRequest();
+ expect(request.get('key')).to.not.exist;
+ expect(request.param('key', 'defaultValue')).to.equal('defaultValue');
+ });
+
+ it('should return undefined, when not found in params/body/query', function() {
+ request = mockRequest.createRequest();
+ expect(request.get('key')).to.not.exist;
+ expect(request.param('key')).to.be.undefined;
+ });
+
});
describe('helper functions', function() {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-mocks-http.git
More information about the Pkg-javascript-commits
mailing list