utils.js
This file
Path
test/support/utils.js
58 lines · 1.2 KiB · JavaScript
Last changed by
tests: add express.static test suiteDouglas Christopher Wilsonbefore adoption6f7a830
History of this fileTake it
The walk stopped after 200 commits: lines older than 76bf96e point at it.
deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e
lines 1–5why, one step back12/**3 * Module dependencies.4 * @private5 */tests: add express.static test suiteDouglas Christopher Wilsonbefore adoption6f7a830
line 6why, one step back6deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e
line 7why, one step back7var assert = require('assert');tests: add express.static test suiteDouglas Christopher Wilsonbefore adoption6f7a830
line 8why, one step back8var Buffer = require('safe-buffer').Bufferdeps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e
lines 9–13why, one step back910/**11 * Module exports.12 * @public13 */tests: add express.static test suiteDouglas Christopher Wilsonbefore adoption6f7a830
lines 14–16why, one step back1415exports.shouldHaveBody = shouldHaveBody16exports.shouldNotHaveBody = shouldNotHaveBodydeps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e
line 17why, one step back17exports.shouldNotHaveHeader = shouldNotHaveHeader;tests: add express.static test suiteDouglas Christopher Wilsonbefore adoption6f7a830
lines 18–46why, one step back1819/**20 * Assert that a supertest response has a specific body.21 *22 * @param {Buffer} buf23 * @returns {function}24 */2526function shouldHaveBody (buf) {27 return function (res) {28 var body = !Buffer.isBuffer(res.body)29 ? Buffer.from(res.text)30 : res.body31 assert.ok(body, 'response has body')32 assert.strictEqual(body.toString('hex'), buf.toString('hex'))33 }34}3536/**37 * Assert that a supertest response does not have a body.38 *39 * @returns {function}40 */4142function shouldNotHaveBody () {43 return function (res) {44 assert.ok(res.text === '' || res.text === undefined)45 }46}deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e
lines 47–58why, one step back4748/**49 * Assert that a supertest response does not have a header.50 *51 * @param {string} header Header name to check52 * @returns {function}53 */54function shouldNotHaveHeader(header) {55 return function (res) {56 assert.ok(!(header.toLowerCase() in res.headers), 'should not have header ' + header);57 };58}