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