Code coverage report for .readme/includes/Assertion/AssertionExample.js

Statements: 87.5% (7 / 8)      Branches: 50% (1 / 2)      Functions: 100% (1 / 1)      Lines: 87.5% (7 / 8)      Ignored: none     

All files » .readme/includes/Assertion/ » AssertionExample.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 40 41 42 43 44 45 46 47    1     1                       2                 1           1         1           1      
 
/// Assertion builder
var Assertion = Divhide.Assertion;
 
/// Create the custom Assert facility
var Assert = new Assertion({
 
    /**
     *
     * Tests if the string starts with the given value
     *
     * @param  {String} val
     * @param  {String} str
     * @return {String}
     */
    startsWith: function(val, str){
 
        Iif(val.indexOf(str) !== 0){
            throw new Error("Does not starts with " + str);
        }
 
    }
 
});
 
/// Test if the value is valid
var isValid = Assert
                .required()
                .string()
                .startsWith("Mary")
                .isValid("Mary and Peter");
 
expect(isValid)
    .toBe(true)
 
 
/// Assert value
var value = Assert
            .required()
            .string()
            .startsWith("Mary")
            .assert("Mary and Peter");
 
expect(value)
    .equals("Mary and Peter");