{"name":"mock-res","version":"0.6.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":"e3b78416553b77b04311152c55eaf6e6bfc42f8c","homepage":"https://github.com/diachedelic/mock-res#readme","_id":"mock-res@0.6.0","_nodeVersion":"16.4.1","_npmVersion":"7.18.1","dist":{"integrity":"sha512-FCX7To1rh+0d+CaZNTU+3TF7IyhTRfsw5zwg6l8g+g7p6l46CwIyGMWV9dL8KuCrVx+ONPKrWi7C5J1eAUVPKA==","shasum":"0543879ba2a1eb9511806c490a0c256e61eb74da","tarball":"http://registry-npm.ywwl.com/mock-res/download/mock-res-0.6.0.tgz","fileCount":5,"unpackedSize":10484,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh2zeGCRA9TVsSAnZWagAAfC4P/14y6K23QudChM0g7bOx\nQOtAqx68ir7m/Xu9GNi6++9zsDfI85Jg74ktVuX1JrO8VXXRTuTW40+poVBN\nUhU9otYQXArPeVdo8UT31HUklGIBaP9J/xEnkt1ieheSEIgGhtJR/3oXqGKN\n+u1BO0HCaEMnr2N5pq2E1JyK3x8P/iEsQugBZ/UJuom+qgtDMEFr3J6bojaZ\n1Z/tzkSv+/QI9l/JtT0+Cs1h0I30Dbf0zsmJWiO8HK4dW6FmKftsL3ucBhzT\n9NmB6lOMlBI2uId84nBcSTA5A5OqTjs7xPlT84deNqKlZQPT42xwiejE68Or\nwPaP3k0KutrzjGhEFcLpe1q9lxgE95TNOghMOKul8mGUPbZXTEM0gRI8qtxk\ngiIPcVjmkkZTIwVRC9H/3CmWdpRzVPJ+dVC5rUTjSlrDGzu4SivI0In7Dm2C\noQcPqGH3/kqUxH4yRJ1DMzS5F0i0LGJyY/kkv5r2BO1J8vYaV94LM31v4sIR\nK74xSOVUyF2zPW0hJajN55RECszRjZUBiOCrBGQ8YKytgpT0Tj0cGq2lKTFI\nHDlPaDeQRsb/i+k9gnR+j/pb1cGbJoZmjZU/oieZfKhrIFT6aZkt959D9sm3\nOTP7PIGrWFBuKabPcnB34y82XfheHaM/6ou67Ab4eyTyyG2N4n75zc334q0g\nPGme\r\n=qfmS\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIG6tR0cy5jXNbaO1Jucz5yghI2hqxHBcI52je/pjaqfqAiBpi1srpbJyKbuCp9nFG7or1+s6+PwaLXXf8s0uEd4+qQ=="}],"size":3680,"noattachment":false,"key":"/mock-res/-/mock-res-0.6.0.tgz"},"_npmUser":{"name":"diachedelic","email":"james@diacono.com.au"},"directories":{},"maintainers":[{"name":"diachedelic","email":"james@diacono.com.au"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mock-res_0.6.0_1635136790829_0.6884085373810427"},"_hasShrinkwrap":false,"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":1635136790958,"_cnpm_publish_time":1635136790958,"dist-tags":{"latest":"0.6.0"}}