MCPcopy
hub / github.com/forwardemail/supertest / _assertBody

Method _assertBody

lib/test.js:240–266  ·  view source on GitHub ↗
(body, res)

Source from the content-addressed store, hash-verified

238 * @api private
239 */// eslint-disable-next-line class-methods-use-this
240 _assertBody(body, res) {
241 const isRegexp = body instanceof RegExp;
242
243 // parsed
244 if (typeof body === 'object' && !isRegexp) {
245 try {
246 deepStrictEqual(body, res.body);
247 } catch (err) {
248 const a = inspect(body);
249 const b = inspect(res.body);
250 return error('expected ' + a + ' response body, got ' + b, body, res.body);
251 }
252 } else if (body !== res.text) {
253 // string
254 const a = inspect(body);
255 const b = inspect(res.text);
256
257 // regexp
258 if (isRegexp) {
259 if (!body.test(res.text)) {
260 return error('expected body ' + b + ' to match ' + body, body, res.body);
261 }
262 } else {
263 return error('expected ' + a + ' response body, got ' + b, body, res.body);
264 }
265 }
266 }
267
268 /**
269 * Perform assertions on a response header and return an Error upon failure.

Callers

nothing calls this directly

Calls 1

errorFunction · 0.85

Tested by

no test coverage detected