{"_id":"mock-req","_rev":"204931","name":"mock-req","description":"Mocks node.js `http.IncomingMessage` (a request).  See also `mock-res`.","dist-tags":{"latest":"0.2.0"},"maintainers":[{"name":"diachedelic","email":"james@diacono.com.au"}],"time":{"modified":"2021-06-03T13:11:53.000Z","created":"2014-03-02T06:10:16.307Z","0.2.0":"2015-03-04T12:29:29.539Z","0.1.0":"2014-03-02T06:10:16.307Z"},"users":{},"author":{"name":"James Diacono"},"repository":{"type":"git","url":"https://github.com/diachedelic/mock-req.git"},"versions":{"0.2.0":{"name":"mock-req","version":"0.2.0","description":"Mocks node.js `http.IncomingMessage` (a request).  See also `mock-res`.","main":"index.js","scripts":{"test":"node test.js"},"repository":{"type":"git","url":"https://github.com/diachedelic/mock-req.git"},"keywords":["mock","IncomingMessage","req","request","test","stub"],"author":{"name":"James Diacono"},"license":"MIT","bugs":{"url":"https://github.com/diachedelic/mock-req/issues"},"gitHead":"afc0f80878c4a201f9f2ee229d5da16d489e313e","homepage":"https://github.com/diachedelic/mock-req","_id":"mock-req@0.2.0","_shasum":"749446804d2c006169342ee7be6bba1cffd534c2","_from":".","_npmVersion":"2.6.1","_nodeVersion":"0.10.22","_npmUser":{"name":"diachedelic","email":"james@diacono.com.au"},"maintainers":[{"name":"diachedelic","email":"james@diacono.com.au"}],"dist":{"shasum":"749446804d2c006169342ee7be6bba1cffd534c2","size":3278,"noattachment":false,"key":"/mock-req/-/mock-req-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/mock-req/download/mock-req-0.2.0.tgz"},"directories":{},"publish_time":1425472169539,"_cnpm_publish_time":1425472169539,"_hasShrinkwrap":false},"0.1.0":{"name":"mock-req","version":"0.1.0","description":"Mocks node.js `http.IncomingMessage` (a request).  See also `mock-res`.","main":"index.js","scripts":{"test":"node test.js"},"repository":{"type":"git","url":"https://github.com/diachedelic/mock-req.git"},"keywords":["mock","IncomingMessage","req","request","test","stub"],"author":{"name":"James Diacono"},"license":"MIT","bugs":{"url":"https://github.com/diachedelic/mock-req/issues"},"_id":"mock-req@0.1.0","dist":{"shasum":"8d7c3df2a9ca544a8881426097f3057976273031","size":3198,"noattachment":false,"key":"/mock-req/-/mock-req-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/mock-req/download/mock-req-0.1.0.tgz"},"_from":".","_npmVersion":"1.3.8","_npmUser":{"name":"diachedelic","email":"james@diacono.com.au"},"maintainers":[{"name":"diachedelic","email":"james@diacono.com.au"}],"directories":{},"publish_time":1393740616307,"_cnpm_publish_time":1393740616307,"_hasShrinkwrap":false}},"readme":"mock-req\n========\n\nMocks node.js `http.IncomingMessage` (a request).  See also `mock-res`.\n\nBeing a readable/writable stream, you can pipe the request body to and from it.\n\n# Usage\nSee `test.js` for further usage.\n\n\tvar MockReq = require('mock-req');\n\n\t// Basic usage\n\tvar req = new MockReq();\n\n\t// With options\n\tvar req = new MockReq({\n\t\tmethod: 'PUT',\n\t\turl: '/stuff?q=thing',\n\t\theaders: {\n\t\t\t'Accept': 'text/plain'\n\t\t},\n\n\t\t// arbitrary properties:\n\t\tsearch: 'thing'\n\t});\n\n\t// Write body\n\treq.write('hello');\n\treq.write('world');\n\n\t// Or stringify to JSON\n\treq.write({\n\t\tval: 5\n\t});\n\n\t// Or even buffers\n\treq.write(new Buffer('buf'));\n\n\t// End body\n\treq.end();\n\n\t// NOTE req.end() is automatically called if \n\t// method is set to GET/HEAD/DELETE.\n\n## Example test case\n\n\tvar assert = require('assert');\n\tvar ping = require('./ping-handler');\n\tvar MockReq = require('mock-req');\n\n\tfunction test(done) {\n\t\t/* Arrange */\n\t\tvar req = new MockReq({\n\t\t\tmethod: 'GET',\n\t\t\turl: '/stuff',\n\t\t\theaders: {\n\t\t\t\t'Accept': 'text/plain'\n\t\t\t}\n\t\t});\n\n\t\t// NOTE: `req.end()` is automatically called for GET/HEAD/DELETE methods\n\n\t\t// Use `mock-res` for a better mock\n\t\tvar res = {\n\t\t\tend: end\n\t\t};\n\n\t\t/* Act */\n\t\tping(req, res);\n\n\t\t/* Assert */\n\t\tfunction end(data) {\n\t\t\tassert.equal(data, 'okay');\n\n\t\t\tdone(); // this is an async test\n\t\t}\n\t}\n\n## Options\nThe options parameter is optional.\n\n* `method`: The request's method, defaults to 'GET'\n* `url`: The request's URL, defaults to ''\n* `headers`: A case insensitive name/value object\n\nAll other values will be copied to the request.\n\n## Methods\n\n* All readable/writable stream methods.\n* `req._fail(error)` Causes the request to emit an `error` when written to.","_attachments":{},"homepage":"https://github.com/diachedelic/mock-req","bugs":{"url":"https://github.com/diachedelic/mock-req/issues"},"license":"MIT"}