Skip to content

Commit

Permalink
[fixed] array.ensure()
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Apr 19, 2016
1 parent 3c0b899 commit 6c309e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
12 changes: 11 additions & 1 deletion test/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])
})

Expand Down Expand Up @@ -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([])
})
})

0 comments on commit 6c309e4

Please sign in to comment.