Skip to content

Commit 6c309e4

Browse files
committed
[fixed] array.ensure()
1 parent 3c0b899 commit 6c309e4

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/array.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ inherits(ArraySchema, MixedSchema, {
138138
ensure() {
139139
return this
140140
.default([])
141-
.transform(val => val != null ? [] : [].concat(val))
141+
.transform(val => val == null ? [] : [].concat(val))
142142
},
143143

144144
compact(rejector){

test/array.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe('Array types', function(){
102102
await inst.isValid([7, 3]).should.become(false)
103103

104104
let value = await inst.validate(['4', 3])
105-
105+
106106
value.should.eql([4, 3])
107107
})
108108

@@ -153,4 +153,14 @@ describe('Array types', function(){
153153
inst.compact(function(v){ return v == null })
154154
.cast(arr).should.eql(['', 1, 0, 4, false])
155155
})
156+
157+
it('should ensure arrays', function(){
158+
var inst = array().ensure()
159+
160+
inst.cast([1, 4])
161+
.should.eql([1, 4])
162+
163+
inst.cast(null)
164+
.should.eql([])
165+
})
156166
})

0 commit comments

Comments
 (0)