7 var assert
= require('assert');
8 var Buffer
= require('safe-buffer').Buffer
15 exports
.shouldHaveBody
= shouldHaveBody
16 exports
.shouldHaveHeader
= shouldHaveHeader
17 exports
.shouldNotHaveBody
= shouldNotHaveBody
18 exports
.shouldNotHaveHeader
= shouldNotHaveHeader
;
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
);