[Pkg-javascript-commits] [node-mocks-http] 289/296: fixed issue with req.param not returning when falsy

Thorsten Alteholz alteholz at moszumanska.debian.org
Mon Feb 8 18:13:46 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 da922fd278d9b2856ec66f2d8c42b1f888677553
Author: Garrett Heaver <garrett at iterationfour.com>
Date:   Mon Jan 4 15:46:06 2016 +0000

    fixed issue with req.param not returning when falsy
---
 lib/mockRequest.js           |  6 +++---
 test/lib/mockRequest.spec.js | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/lib/mockRequest.js b/lib/mockRequest.js
index 183c03e..5f51645 100644
--- a/lib/mockRequest.js
+++ b/lib/mockRequest.js
@@ -163,11 +163,11 @@ function createRequest(options) {
      *   - req.query
      */
     mockRequest.param = function(parameterName, defaultValue) {
-        if (mockRequest.params[parameterName]) {
+        if (null != mockRequest.params[parameterName]) {
             return mockRequest.params[parameterName];
-        } else if (mockRequest.body[parameterName]) {
+        } else if (null != mockRequest.body[parameterName]) {
             return mockRequest.body[parameterName];
-        } else if (mockRequest.query[parameterName]) {
+        } else if (null != mockRequest.query[parameterName]) {
             return mockRequest.query[parameterName];
         }
         return defaultValue;
diff --git a/test/lib/mockRequest.spec.js b/test/lib/mockRequest.spec.js
index 5fdbcfd..af2ea45 100644
--- a/test/lib/mockRequest.spec.js
+++ b/test/lib/mockRequest.spec.js
@@ -370,6 +370,17 @@ describe('mockRequest', function() {
       expect(request.param('key')).to.equal('value');
     });
 
+    it('should return falsy param, when found in params', function() {
+      var options = {
+        params: {
+          key: 0
+        }
+      };
+
+      request = mockRequest.createRequest(options);
+      expect(request.param('key')).to.equal(0);
+    });
+
     it('should return param, when found in body', function() {
       var options = {
         body: {
@@ -381,6 +392,17 @@ describe('mockRequest', function() {
       expect(request.param('key')).to.equal('value');
     });
 
+    it('should return falsy param, when found in body', function() {
+      var options = {
+        body: {
+          key: 0
+        }
+      };
+
+      request = mockRequest.createRequest(options);
+      expect(request.param('key')).to.equal(0);
+    });
+
     it('should return param, when found in query', function() {
       var options = {
         query: {
@@ -392,6 +414,17 @@ describe('mockRequest', function() {
       expect(request.param('key')).to.equal('value');
     });
 
+    it('should return falsy param, when found in query', function() {
+      var options = {
+        query: {
+          key: 0
+        }
+      };
+
+      request = mockRequest.createRequest(options);
+      expect(request.param('key')).to.equal(0);
+    });
+
     it('should not return param, when not found in params/body/query', function() {
       request = mockRequest.createRequest();
       expect(request.get('key')).to.not.exist;

-- 
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