-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
787 additions
and
233 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import assert from 'assert'; | ||
import { format } from 'util'; | ||
import validator from '../src/index'; | ||
|
||
export default function test(options) { | ||
const args = options.args || []; | ||
|
||
args.unshift(null); | ||
|
||
if (options.error) { | ||
options.error.forEach((error) => { | ||
args[0] = error; | ||
|
||
try { | ||
assert.throws(() => validator[options.validator](...args)); | ||
} catch (err) { | ||
const warning = format( | ||
'validator.%s(%s) passed but should error', | ||
options.validator, args.join(', ') | ||
); | ||
|
||
throw new Error(warning); | ||
} | ||
}); | ||
} | ||
|
||
if (options.valid) { | ||
options.valid.forEach((valid) => { | ||
args[0] = valid; | ||
|
||
if (validator[options.validator](...args) !== true) { | ||
const warning = format( | ||
'validator.%s(%s) failed but should have passed', | ||
options.validator, args.join(', ') | ||
); | ||
|
||
throw new Error(warning); | ||
} | ||
}); | ||
} | ||
|
||
if (options.invalid) { | ||
options.invalid.forEach((invalid) => { | ||
args[0] = invalid; | ||
|
||
if (validator[options.validator](...args) !== false) { | ||
const warning = format( | ||
'validator.%s(%s) passed but should have failed', | ||
options.validator, args.join(', ') | ||
); | ||
|
||
throw new Error(warning); | ||
} | ||
}); | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.