Skip to content

Commit

Permalink
test(testFunctions): display stringified arguments in error message (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
pano9000 authored Aug 25, 2024
1 parent f2b1082 commit 96ff3b2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions test/testFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import assert from 'assert';
import { format } from 'util';
import validator from '../src/index';

function stringifyArgs(argsArr) {
return argsArr.map(arg => JSON.stringify(arg)).join(', ');
}

export default function test(options) {
const args = options.args || [];

Expand All @@ -16,7 +20,7 @@ export default function test(options) {
} catch (err) {
const warning = format(
'validator.%s(%s) passed but should error',
options.validator, args.join(', ')
options.validator, stringifyArgs(args)
);

throw new Error(warning);
Expand All @@ -31,7 +35,7 @@ export default function test(options) {
if (validator[options.validator](...args) !== true) {
const warning = format(
'validator.%s(%s) failed but should have passed',
options.validator, args.join(', ')
options.validator, stringifyArgs(args)
);

throw new Error(warning);
Expand All @@ -46,7 +50,7 @@ export default function test(options) {
if (validator[options.validator](...args) !== false) {
const warning = format(
'validator.%s(%s) passed but should have failed',
options.validator, args.join(', ')
options.validator, stringifyArgs(args)
);

throw new Error(warning);
Expand Down

0 comments on commit 96ff3b2

Please sign in to comment.