@@ -20,6 +20,18 @@ function runValidations(validations, endEarly, value, path) {
20
20
return endEarly ? Promise . all ( validations ) : _ . collectErrors ( validations , value , path ) ;
21
21
}
22
22
23
+ function extractTestParams ( name , message , test , useCallback ) {
24
+ var opts = name ;
25
+
26
+ if ( typeof message === 'function' ) test = message , message = locale . default ;
27
+
28
+ if ( typeof name === 'string' || name === null ) opts = { name : name , test : test , message : message , useCallback : useCallback , exclusive : false } ;
29
+
30
+ if ( typeof opts . test !== 'function' ) throw new TypeError ( '`test` is a required parameters' ) ;
31
+
32
+ return opts ;
33
+ }
34
+
23
35
module . exports = SchemaType ;
24
36
25
37
function SchemaType ( ) {
@@ -247,17 +259,9 @@ SchemaType.prototype = {
247
259
* the previous tests are removed and further tests of the same name will replace each other.
248
260
*/
249
261
test : function test ( name , message , _test , useCallback ) {
250
- var opts = name ,
262
+ var opts = extractTestParams ( name , message , _test , useCallback ) ,
251
263
next = this . clone ( ) ;
252
264
253
- if ( typeof name === 'string' ) {
254
- if ( typeof message === 'function' ) _test = message , message = name , name = null ;
255
-
256
- opts = { name : name , test : _test , message : message , useCallback : useCallback , exclusive : false } ;
257
- }
258
-
259
- if ( typeof opts . message !== 'string' || typeof opts . test !== 'function' ) throw new TypeError ( '`message` and `test` are required parameters' ) ;
260
-
261
265
var validate = createValidation ( opts ) ;
262
266
263
267
var isExclusive = opts . exclusive || opts . name && next . _exclusive [ opts . name ] === true ;
0 commit comments