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

Function wrapAssertFn

lib/test.js:358–379  ·  view source on GitHub ↗

* Wraps an assert function into another. * The wrapper function edit the stack trace of any assertion error, prepending a more useful stack to it. * * @param {Function} assertFn * @returns {Function} wrapped assert function

(assertFn)

Source from the content-addressed store, hash-verified

356 */
357
358function wrapAssertFn(assertFn) {
359 const savedStack = new Error().stack.split('\n').slice(3);
360
361 return function(res) {
362 let badStack;
363 let err;
364 try {
365 err = assertFn(res);
366 } catch (e) {
367 err = e;
368 }
369 if (err instanceof Error && err.stack) {
370 badStack = err.stack.replace(err.message, '').split('\n').slice(1);
371 err.stack = [err.toString()]
372 .concat(savedStack)
373 .concat('----')
374 .concat(badStack)
375 .join('\n');
376 }
377 return err;
378 };
379}
380
381/**
382 * Return an `Error` with `msg` and results properties.

Callers 1

expectMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…