Code coverage report for .readme/includes/Assert/AssertExample.js

Statements: 100% (8 / 8)      Branches: 100% (0 / 0)      Functions: 100% (1 / 1)      Lines: 100% (8 / 8)      Ignored: none     

All files » .readme/includes/Assert/ » AssertExample.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39  1     1             1         1         1         1   1             1      
 
var Assert = Divhide.Assert;
 
/// Test if the value is valid
var isValid = Assert.required()
    .string()
    .regex("^M")
    .max(10)
    .min(5)
    .isValid("Mary");
 
expect(isValid)
    .toBe(false);
 
 
/// Valid assertion:
var obj = Assert.required()
    .array()
    .max(5)
    .assert([1, 2, 4, 5]);
 
expect(obj)
    .equals([1, 2, 4, 5]);
 
 
/// Invalid assertion:
var fn = function(){
 
    Assert.required()
        .array()
        .max(1) /// will be on array context
        .assert(["first", "second"]);
 
};
 
expect(fn)
    .toThrow();