diff --git a/src/array.js b/src/array.js index 40e3a80a5..75ddd016b 100644 --- a/src/array.js +++ b/src/array.js @@ -138,7 +138,7 @@ inherits(ArraySchema, MixedSchema, { ensure() { return this .default([]) - .transform(val => val != null ? [] : [].concat(val)) + .transform(val => val == null ? [] : [].concat(val)) }, compact(rejector){ diff --git a/test/array.js b/test/array.js index 5956645aa..0a4603840 100644 --- a/test/array.js +++ b/test/array.js @@ -102,7 +102,7 @@ describe('Array types', function(){ await inst.isValid([7, 3]).should.become(false) let value = await inst.validate(['4', 3]) - + value.should.eql([4, 3]) }) @@ -153,4 +153,14 @@ describe('Array types', function(){ inst.compact(function(v){ return v == null }) .cast(arr).should.eql(['', 1, 0, 4, false]) }) + + it('should ensure arrays', function(){ + var inst = array().ensure() + + inst.cast([1, 4]) + .should.eql([1, 4]) + + inst.cast(null) + .should.eql([]) + }) })