Skip to content

Commit 96ff3b2

Browse files
authored
test(testFunctions): display stringified arguments in error message (#2442)
1 parent f2b1082 commit 96ff3b2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

test/testFunctions.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import assert from 'assert';
22
import { format } from 'util';
33
import validator from '../src/index';
44

5+
function stringifyArgs(argsArr) {
6+
return argsArr.map(arg => JSON.stringify(arg)).join(', ');
7+
}
8+
59
export default function test(options) {
610
const args = options.args || [];
711

@@ -16,7 +20,7 @@ export default function test(options) {
1620
} catch (err) {
1721
const warning = format(
1822
'validator.%s(%s) passed but should error',
19-
options.validator, args.join(', ')
23+
options.validator, stringifyArgs(args)
2024
);
2125

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

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

5256
throw new Error(warning);

0 commit comments

Comments
 (0)