Skip to content

Commit

Permalink
test: number format via $data, #291
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Feb 10, 2017
1 parent 901343c commit 6bf7d19
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions spec/ajv.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,27 @@ describe('Ajv', function () {
validate(2) .should.equal(true);
validate('abc') .should.equal(true);
});

it('should validate numbers with format via $data', function() {
ajv = new Ajv({$data: true});
ajv.addFormat('positive', {
type: 'number',
validate: function(x) {
return x > 0;
}
});

var validate = ajv.compile({
properties: {
data: { format: { $data: '1/frmt' } },
frmt: { type: 'string' }
}
});
validate({data: -2, frmt: 'positive'}) .should.equal(false);
validate({data: 0, frmt: 'positive'}) .should.equal(false);
validate({data: 2, frmt: 'positive'}) .should.equal(true);
validate({data: 'abc', frmt: 'positive'}) .should.equal(true);
});
});
});

Expand Down

0 comments on commit 6bf7d19

Please sign in to comment.