{"name":"mock-res","version":"0.3.1","description":"Mocks node.js http.ServerResponse. See also `mock-req`.","main":"index.js","scripts":{"test":"node test.js"},"repository":{"type":"git","url":"git+https://github.com/diachedelic/mock-res.git"},"keywords":["mock","http","ServerResponse","response","res"],"author":{"name":"James Diacono"},"license":"MIT","bugs":{"url":"https://github.com/diachedelic/mock-res/issues"},"gitHead":"c8f749adca341db6a21eb5cd9eb4cc4ef25a3322","homepage":"https://github.com/diachedelic/mock-res#readme","_id":"mock-res@0.3.1","_shasum":"abadc6ed11b1a955b0b7c149012d736a9b6d9e9f","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.7.0","_npmUser":{"name":"diachedelic","email":"james@diacono.com.au"},"maintainers":[{"name":"diachedelic","email":"james@diacono.com.au"}],"dist":{"shasum":"abadc6ed11b1a955b0b7c149012d736a9b6d9e9f","tarball":"http://registry-npm.ywwl.com/mock-res/download/mock-res-0.3.1.tgz","integrity":"sha512-gB9OnHO7ZbHI4+DLobkWsR+H/Q07VFYfO2oApgy6ll+ACwX5NfAQBmS+0ljBQXyDqmB8zUkaeXc6F/csGDYLaA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCEyLa0PP5VP9Y4//B/NbP2td9ISa/9U1AvXjPVKvDy1AIhAMJczIhJaOLbu1CSI/INb+NYObs0Bjepa2CovRkXkflX"}],"size":3520,"noattachment":false,"key":"/mock-res/-/mock-res-0.3.1.tgz"},"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/mock-res-0.3.1.tgz_1475241591361_0.1803340995684266"},"directories":{},"readme":"mock-res\n========\n\nMocks node.js http.ServerResponse (a response). See also `mock-req`.\n\nBeing a readable/writable stream, you can pipe the response body to and from it.\n\n# Usage\nSee `test.js` for further usage.\n\n\tvar MockRes = require('mock-res');\n\n\t// Basic usage\n\tvar res = new MockRes();\n\n\t// Supply a callback to be called after res.end() is called\n\tvar res = new MockRes(function onEnd() {\n\t\tconsole.log('Response sent');\n\t});\n\n\t// Listen for stream events\n\tres.on('error', function (err) {\n\t\t// If not listened for, the 'error' event will throw,\n\t\t// as is true for any stream.\n\t});\n\tres.on('finish', function () {\n\t\tconsole.log('Finished writing response');\n\t});\n\n\t// Read status code\n\tres.statusCode; // 200 by default\n\n\t// Read body as string\n\tres._getString(); // 'I am a chicken';\n\n\t// Read body as parsed JSON\n\tres._getJSON(); // { chicken: true }\n\n\t// Pipe body somewhere\n\tres.pipe(fs.createWriteStream('/tmp/yo'));\n\n## Example test case\n\n\tvar assert = require('assert');\n\tvar list = require('./list-handler');\n\tvar MockRes = require('mock-res');\n\n\tfunction test(done) {\n\t\t/* Arrange */\n\n\t\t// Use `mock-req` for a better mock\n\t\tvar req = {\n\t\t\tmethod: 'GET',\n\t\t\turl: '/foos'\n\t\t}\n\n\t\tvar res = new MockRes(onEnd);\n\n\t\t/* Act */\n\t\tlist(req, res);\n\n\t\t/* Assert */\n\t\tfunction onEnd() {\n\t\t\t// NOTE `this` === `res`\n\n\t\t\tassert.equal(this.statusCode, 200);\n\t\t\tassert.equal(this._getString(), '[{\"id\":0},{\"id\":1}]');\n\t\t\tassert.deepEqual(this._getJSON(), [{id: 0 }, {id: 1 }]);\n\t\t\tassert.deepEqual(this.getHeader('set-cookie'), ['a=1', 'b=2']);\n\n\t\t\tres.pipe(process.stdout); // `res` is just a readable stream here\n\n\t\t\tdone(); // this is an async test\n\t\t}\n\t}\n\n## Methods\n\n* All readable/writable stream methods.\n* `writeHead(statusCode, [reasonPhrase], [headers])` Sets the response status code, status message, and headers.  See also the [`http.ServerResponse` documentation](http://nodejs.org/api/http.html#http_response_writehead_statuscode_reasonphrase_headers).\n* `setHeader()`, `getHeader()`, `getHeaders()`, `removeHeader()`\n* `_getString()` Reads the body as a string, from the internal stream buffer.\n* `_getJSON()` Reads the body as a parsed JSON object, from the internal stream buffer.\n","publish_time":1475241592486,"_cnpm_publish_time":1475241592486,"dist-tags":{"latest":"0.6.0"}}