commit
a6df5867f1
|
@ -260,7 +260,7 @@ describe('Type coercion', function () {
|
|||
});
|
||||
|
||||
|
||||
it('should coerce to multiple types in order', function() {
|
||||
it('should coerce to multiple types in order with number type', function() {
|
||||
var schema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
|
@ -302,6 +302,45 @@ describe('Type coercion', function () {
|
|||
});
|
||||
});
|
||||
|
||||
it('should coerce to multiple types in order with integer type', function() {
|
||||
var schema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: {
|
||||
type: [ 'integer', 'boolean', 'null' ]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
instances.forEach(function (_ajv) {
|
||||
var data;
|
||||
|
||||
_ajv.validate(schema, data = { foo: '1' }) .should.equal(true);
|
||||
data .should.eql({ foo: 1 });
|
||||
|
||||
_ajv.validate(schema, data = { foo: 'false' }) .should.equal(true);
|
||||
data .should.eql({ foo: false });
|
||||
|
||||
_ajv.validate(schema, data = { foo: 1 }) .should.equal(true);
|
||||
data .should.eql({ foo: 1 }); // no coercion
|
||||
|
||||
_ajv.validate(schema, data = { foo: true }) .should.equal(true);
|
||||
data .should.eql({ foo: true }); // no coercion
|
||||
|
||||
_ajv.validate(schema, data = { foo: null }) .should.equal(true);
|
||||
data .should.eql({ foo: null }); // no coercion
|
||||
|
||||
_ajv.validate(schema, data = { foo: 'abc' }) .should.equal(false);
|
||||
data .should.eql({ foo: 'abc' }); // can't coerce
|
||||
|
||||
_ajv.validate(schema, data = { foo: {} }) .should.equal(false);
|
||||
data .should.eql({ foo: {} }); // can't coerce
|
||||
|
||||
_ajv.validate(schema, data = { foo: [] }) .should.equal(false);
|
||||
data .should.eql({ foo: [] }); // can't coerce
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should fail to coerce non-number if multiple properties/items are coerced (issue #152)', function() {
|
||||
var schema = {
|
||||
|
|
Loading…
Reference in New Issue