Skip to content
Myr

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 file

Take it

Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6

lines 1–5why, one step back
1
2/**3 * Module dependencies.4 * @private5 */

Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99

line 6why, one step back
6

Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6

line 7why, one step back
7var assert = require('assert');

Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99

line 8why, one step back
8var Buffer = require('safe-buffer').Buffer

Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6

lines 9–13why, one step back
9
10/**11 * Module exports.12 * @public13 */

Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99

lines 14–15why, one step back
14
15exports.shouldHaveBody = shouldHaveBody

Merge tag '4.19.0' into 5.xWes Toddbefore adoptione9f9aae

line 16why, one step back
16exports.shouldHaveHeader = shouldHaveHeader

Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99

line 17why, one step back
17exports.shouldNotHaveBody = shouldNotHaveBody

Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6

line 18why, one step back
18exports.shouldNotHaveHeader = shouldNotHaveHeader;

Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99

lines 19–33why, one step back
19
20/**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 back
34 }
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 back
47 }
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 back
61
62/**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}