Code coverage report for .readme/includes/Schema/SchemaNumberExample.js

Statements: 100% (16 / 16)      Branches: 100% (0 / 0)      Functions: 100% (2 / 2)      Lines: 100% (16 / 16)      Ignored: none     

All files » .readme/includes/Schema/ » SchemaNumberExample.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 48 49 50 51 52 53  1   1               1 1       1 1       1   1               1   1               1 1     1 1     1 1    
 
var Schema = Divhide.Schema;
 
var schema = Schema.number()
                .optional()
                .min(3)
                .max(5)
                .compile();
 
 
/// value is correct
var value = schema.value(3);
expect(value).toBe(3);
 
 
/// optional value
var value = schema.value();
expect(value).equals(null);
 
 
/// value is undefined
expect(
    function(){
        schema.value(0);
    })
    .toThrow(
        new Error("The minimum value allowed is 3.")
    );
 
 
/// values exceed the max
expect(
    function(){
        schema.value(10);
    })
    .toThrow(
        new Error("The maximum value allowed is 5.")
    );
 
 
/// because is optional, is valid!
var isValid = schema.isValid();
expect(isValid).toBe(true);
 
 
isValid = schema.isValid(3);
expect(isValid).toBe(true);
 
 
isValid = schema.isValid(10);
expect(isValid).toBe(false);