silfverorg / duns.js

Javascript schema validator
5 stars 2 forks source link

Syntax for assert #36

Closed br0r closed 9 years ago

br0r commented 9 years ago

What is the current syntax for assert?

If I look in the tests it's Duns.number(100).assert;

But in the code assert is a function.

Shouldn't the syntax be Duns.assert(value, schema);?

silfverstrom commented 9 years ago

Are you perhaps referring to this line in the anyvalidator-test?

(Duns.any(undefined).assert).should.throw();

This is a syntax-confusion with mocha/should. You give the function, without executing it, to the should-validator. It is then later on executed(this is so should can wrap it inside a try/catch block).

Thus, the syntax for using assert in duns is,

var schema = Duns.object().keys({
test : Duns.number(),
});

schema.init('100').assert(); //throws
schema.assert('100'); //throws
silfverstrom commented 9 years ago

The documentation has been updated to illuminate this syntax.