From 6bf7d19ff243a265205147fc4e7ed471be2c2659 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Fri, 10 Feb 2017 21:59:20 +0000 Subject: [PATCH] test: number format via $data, #291 --- spec/ajv.spec.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/spec/ajv.spec.js b/spec/ajv.spec.js index 024005b13..d0fb3de3e 100644 --- a/spec/ajv.spec.js +++ b/spec/ajv.spec.js @@ -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); + }); }); });