Skip to content

Instantly share code, notes, and snippets.

@sidferreira
Created July 8, 2020 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sidferreira/6af1edbb41aa9b3f638b2f912d3003f8 to your computer and use it in GitHub Desktop.
Save sidferreira/6af1edbb41aa9b3f638b2f912d3003f8 to your computer and use it in GitHub Desktop.
export default function fixJestErrorStack(error: Error) {
if (error.stack) {
const lines: string[] = error.stack.split('\n');
let indexToRemove = -1;
lines.forEach((line, index) => {
if (indexToRemove === -1 && line.match(new RegExp(/^\s+at /))) {
indexToRemove = index;
}
});
if (indexToRemove >= 0) {
lines.splice(indexToRemove, 1);
}
error.stack = lines.join('\n');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment