fix(deps)!: mime-types@^3.0.0 (#5882)
[express.git] / test / support / utils.js
blob5b4062e0b2af18f8da4c4e30e204c51b1b4b26e3
2 /**
3 * Module dependencies.
4 * @private
5 */
7 var assert = require('assert');
8 var Buffer = require('safe-buffer').Buffer
10 /**
11 * Module exports.
12 * @public
15 exports.shouldHaveBody = shouldHaveBody
16 exports.shouldHaveHeader = shouldHaveHeader
17 exports.shouldNotHaveBody = shouldNotHaveBody
18 exports.shouldNotHaveHeader = shouldNotHaveHeader;
20 /**
21 * Assert that a supertest response has a specific body.
23 * @param {Buffer} buf
24 * @returns {function}
27 function shouldHaveBody (buf) {
28 return function (res) {
29 var body = !Buffer.isBuffer(res.body)
30 ? Buffer.from(res.text)
31 : res.body
32 assert.ok(body, 'response has body')
33 assert.strictEqual(body.toString('hex'), buf.toString('hex'))
37 /**
38 * Assert that a supertest response does have a header.
40 * @param {string} header Header name to check
41 * @returns {function}
44 function shouldHaveHeader (header) {
45 return function (res) {
46 assert.ok((header.toLowerCase() in res.headers), 'should have header ' + header)
50 /**
51 * Assert that a supertest response does not have a body.
53 * @returns {function}
56 function shouldNotHaveBody () {
57 return function (res) {
58 assert.ok(res.text === '' || res.text === undefined)
62 /**
63 * Assert that a supertest response does not have a header.
65 * @param {string} header Header name to check
66 * @returns {function}
68 function shouldNotHaveHeader(header) {
69 return function (res) {
70 assert.ok(!(header.toLowerCase() in res.headers), 'should not have header ' + header);