[Pkg-javascript-commits] [node-mocks-http] 257/296: accept non-standard properties into the request object

Thorsten Alteholz alteholz at moszumanska.debian.org
Mon Feb 8 18:13:42 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 03b435b84547986167a89e5051c14737a194b929
Author: fiiv <mike.timofiiv at gmail.com>
Date:   Mon Sep 7 16:18:32 2015 +0200

    accept non-standard properties into the request object
---
 lib/mockRequest.js           | 9 +++++++++
 test/lib/mockRequest.spec.js | 9 +++++++++
 2 files changed, 18 insertions(+)

diff --git a/lib/mockRequest.js b/lib/mockRequest.js
index 8a93677..5ea7bf2 100644
--- a/lib/mockRequest.js
+++ b/lib/mockRequest.js
@@ -31,6 +31,10 @@
 
 var url = require('url');
 
+var standardRequestOptions = [
+  'method', 'url', 'originalUrl', 'path', 'params', 'session', 'cookies', 'headers', 'body', 'query', 'files'
+];
+
 function convertKeysToLowerCase(map) {
     var newMap = {};
     for(var key in map) {
@@ -71,6 +75,11 @@ function createRequest(options) {
         mockRequest.query = require('querystring').parse(mockRequest.url.split('?')[1]);
     }
 
+    // attach any other provided objects into the request for more advanced testing
+    for (var n in options) {
+      if (standardRequestOptions.indexOf(n) === -1) mockRequest[n] = options[n];
+    }
+
     /**
      * Return request header.
      *
diff --git a/test/lib/mockRequest.spec.js b/test/lib/mockRequest.spec.js
index a08c37d..7a9222c 100644
--- a/test/lib/mockRequest.spec.js
+++ b/test/lib/mockRequest.spec.js
@@ -218,6 +218,15 @@ describe('mockRequest', function() {
         expect(request.query).to.deep.equal(parsedOptions);
       });
 
+      it('should accept and set non-standard options passed to it', function() {
+        var options = {
+          mySampleProp: 'la LA LA'
+        };
+
+        request = mockRequest.createRequest(options);
+        expect(request.mySampleProp).to.equal('la LA LA');
+      });
+
     });
 
   });

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