utils.js
This file
Path
test/support/utils.js
72 lines · 1.5 KiB · JavaScript
Last changed by
Merge tag '4.19.0' into 5.xWes Toddbefore adoptione9f9aae
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–15why, one step back1415exports.shouldHaveBody = shouldHaveBodyMerge tag '4.19.0' into 5.xWes Toddbefore adoptione9f9aae
line 16why, one step back16exports.shouldHaveHeader = shouldHaveHeaderMerge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99
line 17why, one step back17exports.shouldNotHaveBody = shouldNotHaveBodyMerge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6
line 18why, one step back18exports.shouldNotHaveHeader = shouldNotHaveHeader;Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99
lines 19–33why, one step back1920/**21 * Assert that a supertest response has a specific body.22 *23 * @param {Buffer} buf24 * @returns {function}25 */2627function shouldHaveBody (buf) {28 return function (res) {29 var body = !Buffer.isBuffer(res.body)30 ? Buffer.from(res.text)31 : res.body32 assert.ok(body, 'response has body')33 assert.strictEqual(body.toString('hex'), buf.toString('hex'))Merge tag '4.19.0' into 5.xWes Toddbefore adoptione9f9aae
lines 34–46why, one step back34 }35}3637/**38 * Assert that a supertest response does have a header.39 *40 * @param {string} header Header name to check41 * @returns {function}42 */4344function shouldHaveHeader (header) {45 return function (res) {46 assert.ok((header.toLowerCase() in res.headers), 'should have header ' + header)Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99
lines 47–60why, one step back47 }48}4950/**51 * Assert that a supertest response does not have a body.52 *53 * @returns {function}54 */5556function shouldNotHaveBody () {57 return function (res) {58 assert.ok(res.text === '' || res.text === undefined)59 }60}Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6
lines 61–72why, one step back6162/**63 * Assert that a supertest response does not have a header.64 *65 * @param {string} header Header name to check66 * @returns {function}67 */68function shouldNotHaveHeader(header) {69 return function (res) {70 assert.ok(!(header.toLowerCase() in res.headers), 'should not have header ' + header);71 };72}