Skip to content

Commit

Permalink
handle-exception-on-test-case
Browse files Browse the repository at this point in the history
  • Loading branch information
uriva committed Nov 15, 2023
1 parent 138a1b5 commit cc53a51
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,19 @@ const runTestCases = <F extends (input: any) => any>(
(
[input, expected]: TestCase<Parameters<F>[0], ReturnType<F>>,
) => {
const actual = f(input);
const result = equal(actual, expected);
return result
? null
: `\`${JSON.stringify(input)}\` -> \`${
JSON.stringify(actual)
}\` instead of \`${JSON.stringify(expected)}\``;
try {
const actual = f(input);
const result = equal(actual, expected);
return result
? null
: `\`${JSON.stringify(input)}\` -> \`${
JSON.stringify(actual)
}\` instead of \`${JSON.stringify(expected)}\``;
} catch (e) {
return `Threw an exception for input ${
JSON.stringify(input)
}. Here's the stack trace: ${e}`;
}
};

type Options<Input, Output> = {
Expand Down

0 comments on commit cc53a51

Please sign in to comment.