7 var assert
= require('assert');
14 exports
.shouldHaveBody
= shouldHaveBody
15 exports
.shouldHaveHeader
= shouldHaveHeader
16 exports
.shouldNotHaveBody
= shouldNotHaveBody
17 exports
.shouldNotHaveHeader
= shouldNotHaveHeader
;
18 exports
.shouldSkipQuery
= shouldSkipQuery
21 * Assert that a supertest response has a specific body.
27 function shouldHaveBody (buf
) {
28 return function (res
) {
29 var body
= !Buffer
.isBuffer(res
.body
)
30 ? Buffer
.from(res
.text
)
32 assert
.ok(body
, 'response has body')
33 assert
.strictEqual(body
.toString('hex'), buf
.toString('hex'))
38 * Assert that a supertest response does have a header.
40 * @param {string} header Header name to check
44 function shouldHaveHeader (header
) {
45 return function (res
) {
46 assert
.ok((header
.toLowerCase() in res
.headers
), 'should have header ' + header
)
51 * Assert that a supertest response does not have a body.
56 function shouldNotHaveBody () {
57 return function (res
) {
58 assert
.ok(res
.text
=== '' || res
.text
=== undefined)
63 * Assert that a supertest response does not have a header.
65 * @param {string} header Header name to check
68 function shouldNotHaveHeader(header
) {
69 return function (res
) {
70 assert
.ok(!(header
.toLowerCase() in res
.headers
), 'should not have header ' + header
);
74 function getMajorVersion(versionString
) {
75 return versionString
.split('.')[0];
78 function shouldSkipQuery(versionString
) {
79 // Skipping HTTP QUERY tests on Node 21, it is reported in http.METHODS on 21.7.2 but not supported
80 // update this implementation to run on supported versions of 21 once they exist
81 // upstream tracking https://github.com/nodejs/node/issues/51562
82 // express tracking issue: https://github.com/expressjs/express/issues/5615
83 return Number(getMajorVersion(versionString
)) === 21