value-validator
Advanced tools
+1
-0
@@ -64,2 +64,3 @@ 'use strict'; | ||
| console.warn('the callback will be removed in the next major version'); | ||
| this._validate(v).then(function (pass) { | ||
@@ -66,0 +67,0 @@ return callback(null, pass); |
+1
-1
| { | ||
| "name": "value-validator", | ||
| "version": "2.1.1", | ||
| "version": "2.2.0", | ||
| "description": "Low-level rule manager for validating values.", | ||
@@ -5,0 +5,0 @@ "main": "./lib", |
+40
-45
@@ -44,23 +44,18 @@ import test from 'ava' | ||
| test.cb('simple global preset', t => { | ||
| new Validator('mobile').validate('18800001111', (err, result) => { | ||
| t.is(err, null) | ||
| test('simple global preset', t => { | ||
| return new Validator('mobile').validate('18800001111').then(result => { | ||
| t.is(result, true) | ||
| t.end() | ||
| }) | ||
| }) | ||
| test.cb('preset with arguments', t => { | ||
| new Validator('max-length:3').validate('1234', (err, result) => { | ||
| t.is(err, null) | ||
| test('preset with arguments', t => { | ||
| return new Validator('max-length:3').validate('1234').then(result => { | ||
| t.is(result, false) | ||
| t.end() | ||
| }) | ||
| }) | ||
| test.cb('preset with improper length of arguments', t => { | ||
| test('preset with improper length of arguments', t => { | ||
| try { | ||
| new Validator('max-length:1,2') | ||
| } catch (e) { | ||
| t.end() | ||
| return | ||
@@ -70,67 +65,67 @@ } | ||
| t.fail('it should throw an error.') | ||
| t.end() | ||
| }) | ||
| test.cb('multiple presets, [1, 3] test "12"', t => { | ||
| new Validator('max-length:3|min-length:1').validate('12', (err, result) => { | ||
| t.is(err, null) | ||
| test('multiple presets, [1, 3] test "12"', t => { | ||
| return new Validator('max-length:3|min-length:1') | ||
| .validate('12') | ||
| .then(result => { | ||
| t.is(result, true) | ||
| t.end() | ||
| }) | ||
| }) | ||
| test.cb('multiple presets, [1, 3] test "1234"', t => { | ||
| new Validator('max-length:3|min-length:1').validate('1234', (err, result) => { | ||
| t.is(err, null) | ||
| test('multiple presets, [1, 3] test "1234"', t => { | ||
| return new Validator('max-length:3|min-length:1') | ||
| .validate('1234') | ||
| .then(result => { | ||
| t.is(result, false) | ||
| t.end() | ||
| }) | ||
| }) | ||
| test.cb('multiple presets, [1, 3] test ""', t => { | ||
| new Validator('max-length:3|min-length:1').validate('', (err, result) => { | ||
| t.is(err, null) | ||
| test('multiple presets, [1, 3] test ""', t => { | ||
| return new Validator('max-length:3|min-length:1') | ||
| .validate('') | ||
| .then(result => { | ||
| t.is(result, false) | ||
| t.end() | ||
| }) | ||
| }) | ||
| test.cb('async preset, min:6, and username, foo, fail', t => { | ||
| new Validator('min-length:6|username').validate('foo', (err, result) => { | ||
| t.is(err, null) | ||
| test('async preset, min:6, and username, foo, fail', t => { | ||
| return new Validator('min-length:6|username') | ||
| .validate('foo') | ||
| .then(result => { | ||
| t.is(result, false) | ||
| t.end() | ||
| }) | ||
| }) | ||
| test.cb('min-length-6-username, foo, fail', t => { | ||
| new Validator('min-length-6-username').validate('foo', (err, result) => { | ||
| t.is(err, null) | ||
| test('min-length-6-username, foo, fail', t => { | ||
| return new Validator('min-length-6-username') | ||
| .validate('foo') | ||
| .then(result => { | ||
| t.is(result, false) | ||
| t.end() | ||
| }) | ||
| }) | ||
| test.cb('async preset, min:3, and username, foo, fail', t => { | ||
| new Validator('min-length:3|username').validate('foo', (err, result) => { | ||
| t.is(err, 'foo already taken') | ||
| t.is(result, false) | ||
| t.end() | ||
| }) | ||
| test('async preset, min:3, and username, foo, fail', t => { | ||
| return new Validator('min-length:3|username') | ||
| .validate('foo') | ||
| .then( | ||
| () => t.fail('should fail'), | ||
| err => t.is(err, 'foo already taken') | ||
| ) | ||
| }) | ||
| test.cb('async preset, min:3, and username, bar, success', t => { | ||
| new Validator('min-length:3|username').validate('bar', (err, result) => { | ||
| t.is(err, null) | ||
| test('async preset, min:3, and username, bar, success', t => { | ||
| return new Validator('min-length:3|username') | ||
| .validate('bar') | ||
| .then(result => { | ||
| t.is(result, true) | ||
| t.end() | ||
| }) | ||
| }) | ||
| test.cb('preset with multiple arguments', t => { | ||
| new Validator('between:2,6').validate('1234', (err, result) => { | ||
| t.is(err, null) | ||
| test('preset with multiple arguments', t => { | ||
| return new Validator('between:2,6') | ||
| .validate('1234') | ||
| .then(result => { | ||
| t.is(result, true) | ||
| t.end() | ||
| }) | ||
| }) |
@@ -100,4 +100,4 @@ import ava from 'ava' | ||
| const _test = only | ||
| ? ava.only.cb | ||
| : ava.cb | ||
| ? ava.only | ||
| : ava | ||
@@ -112,18 +112,15 @@ _test(description, t => { | ||
| t.fail() | ||
| t.end() | ||
| return | ||
| } | ||
| v.validate(value, (err, success) => { | ||
| t.is(success, result) | ||
| v.validate(value).then( | ||
| success => { | ||
| t.is(success, result) | ||
| }, | ||
| if (err) { | ||
| err => { | ||
| t.is(err.message || err, error) | ||
| } else { | ||
| t.is(err, null) | ||
| } | ||
| t.end() | ||
| }) | ||
| ) | ||
| }) | ||
| }) |
Sorry, the diff of this file is too big to display
123667
3.17%417
-1.42%