From c2c9fe973cac00b179b69a0747f54d3aa4a122cc Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Tue, 25 May 2021 21:15:35 +0100 Subject: [PATCH 1/3] Update length-test.js --- tests/unit/validators/length-test.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/unit/validators/length-test.js b/tests/unit/validators/length-test.js index e26eaf0..cf5bcca 100644 --- a/tests/unit/validators/length-test.js +++ b/tests/unit/validators/length-test.js @@ -15,7 +15,7 @@ test('no options', function(assert) { }); test('allow blank', function(assert) { - assert.expect(2); + assert.expect(4); options = { allowBlank: true, @@ -25,12 +25,18 @@ test('allow blank', function(assert) { result = validate('', cloneOptions(options)); assert.equal(processResult(result), true); + result = validate(' ', cloneOptions(options)); + assert.equal(processResult(result), 'This field is too short (minimum is 5 characters)'); + + result = validate(undefined, cloneOptions(options)); + assert.equal(processResult(result), true); + result = validate('test', cloneOptions(options)); assert.equal(processResult(result), 'This field is too short (minimum is 5 characters)'); }); test('allow none', function(assert) { - assert.expect(2); + assert.expect(3); options = { allowNone: true @@ -40,8 +46,12 @@ test('allow none', function(assert) { assert.equal(processResult(result), true); options.allowNone = false; + result = validate(null, cloneOptions(options)); assert.equal(processResult(result), 'This field is invalid'); + + result = validate('', cloneOptions(options)); + assert.equal(processResult(result), true); }); test('is', function(assert) { From e1b4e31b2fa2d7f5638d46e9a03407a03eaf66d7 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Tue, 25 May 2021 21:26:27 +0100 Subject: [PATCH 2/3] Update presence-test.js --- tests/unit/validators/presence-test.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/unit/validators/presence-test.js b/tests/unit/validators/presence-test.js index 37541bd..3c27d42 100644 --- a/tests/unit/validators/presence-test.js +++ b/tests/unit/validators/presence-test.js @@ -25,13 +25,25 @@ test('presence - value blank', function(assert) { assert.equal(processResult(result), true); }); -test('presence with ignoreBlank - value blank', function(assert) { +test('presence - null value', function(assert) { assert.expect(1); + options = { presence: true }; + + result = validate(null, cloneOptions(options)); + assert.equal(processResult(result), 'This field can\'t be blank'); +}); + +test('presence with ignoreBlank - value blank', function(assert) { + assert.expect(2); + options = { presence: true, ignoreBlank: true }; result = validate(' ', cloneOptions(options)); assert.equal(processResult(result), 'This field can\'t be blank'); + + result = validate(null, cloneOptions(options)); + assert.equal(processResult(result), 'This field can\'t be blank'); }); test('presence - value not present', function(assert) { From 21c6aa36cc11329559d2c136e2bdff3564eee2d7 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Tue, 25 May 2021 21:29:18 +0100 Subject: [PATCH 3/3] Update length-test.js --- tests/unit/validators/length-test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/validators/length-test.js b/tests/unit/validators/length-test.js index cf5bcca..656adbc 100644 --- a/tests/unit/validators/length-test.js +++ b/tests/unit/validators/length-test.js @@ -25,12 +25,12 @@ test('allow blank', function(assert) { result = validate('', cloneOptions(options)); assert.equal(processResult(result), true); - result = validate(' ', cloneOptions(options)); - assert.equal(processResult(result), 'This field is too short (minimum is 5 characters)'); - result = validate(undefined, cloneOptions(options)); assert.equal(processResult(result), true); + result = validate(' ', cloneOptions(options)); + assert.equal(processResult(result), 'This field is too short (minimum is 5 characters)'); + result = validate('test', cloneOptions(options)); assert.equal(processResult(result), 'This field is too short (minimum is 5 characters)'); });