{"name":"mock-res","version":"0.3.0","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":"f9c720342e8f9434e7cc1005b3477f335124c3e1","homepage":"https://github.com/diachedelic/mock-res#readme","_id":"mock-res@0.3.0","_shasum":"0c2034cc6336d0595a3af109f7448283ee9c47f5","_from":".","_npmVersion":"2.11.2","_nodeVersion":"0.12.5","_npmUser":{"name":"diachedelic","email":"james@diacono.com.au"},"maintainers":[{"name":"diachedelic","email":"james@diacono.com.au"}],"dist":{"shasum":"0c2034cc6336d0595a3af109f7448283ee9c47f5","tarball":"http://registry-npm.ywwl.com/mock-res/download/mock-res-0.3.0.tgz","integrity":"sha512-Hh/Mljjp9XI21xOJvs/LO+jEig3uAG8mJcUepJFBJ4INibBbYmb4l2mLqysaphuT5DXWjsQyqGhsd1D3rfNicQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDMqzOOfCsRxIvh4RoPEWg/KLdNCYyLbFC1D4rBUXNv+QIhAL2njI1eY0aDzlPJHsr/bwvsf9fegVwUiZDVNaebOS7x"}],"size":3504,"noattachment":false,"key":"/mock-res/-/mock-res-0.3.0.tgz"},"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":1437103010790,"_cnpm_publish_time":1437103010790,"dist-tags":{"latest":"0.6.0"}}