Skip to content
Myr

utils.js

This file

Path

test/support/utils.js

72 lines · 1.5 KiB · JavaScript

Last changed by

tests: expand res.sendFile options testsDouglas Christopher Wilsonbefore adoption291993d

History of this file

Take it

The walk stopped after 200 commits: lines older than 313d54f point at it.

build: supertest@6.1.6Douglas Christopher Wilsonbefore adoption313d54f

lines 1–15why, one step back
1
2/**3 * Module dependencies.4 * @private5 */67var assert = require('assert');8var Buffer = require('safe-buffer').Buffer910/**11 * Module exports.12 * @public13 */1415exports.shouldHaveBody = shouldHaveBody

tests: expand res.sendFile options testsDouglas Christopher Wilsonbefore adoption291993d

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

build: supertest@6.1.6Douglas Christopher Wilsonbefore adoption313d54f

lines 17–33why, one step back
17exports.shouldNotHaveBody = shouldNotHaveBody
18exports.shouldNotHaveHeader = shouldNotHaveHeader;1920/**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'))

tests: expand res.sendFile options testsDouglas Christopher Wilsonbefore adoption291993d

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)

build: supertest@6.1.6Douglas Christopher Wilsonbefore adoption313d54f

lines 47–72why, 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}6162/**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}