utils.js
This file
Path
test/support/utils.js
58 lines · 1.2 KiB · JavaScript
Last changed by
Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99
History of this fileTake it
Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6
lines 1–5why, one step back12/**3 * Module dependencies.4 * @private5 */Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99
line 6why, one step back6Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6
line 7why, one step back7var assert = require('assert');Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99
line 8why, one step back8var Buffer = require('safe-buffer').BufferMerge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6
lines 9–13why, one step back910/**11 * Module exports.12 * @public13 */Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99
lines 14–16why, one step back1415exports.shouldHaveBody = shouldHaveBody16exports.shouldNotHaveBody = shouldNotHaveBodyMerge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6
line 17why, one step back17exports.shouldNotHaveHeader = shouldNotHaveHeader;Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99
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}Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6
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}