aboutsummaryrefslogtreecommitdiffstats
path: root/tools/node_modules/expresso/test/assert.test.js
blob: 8dbc61055405461fe107e5e983bfac54dc911e45 (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
 * Module dependencies.
 */

var assert = require('assert');

module.exports = {
    'assert.eql()': function(){
        assert.equal(assert.deepEqual, assert.eql);
    },
    
    'assert.type()': function(){
        assert.type('foobar', 'string');
        assert.type(2, 'number');
        assert.throws(function(){
            assert.type([1,2,3], 'string');
        });
    },
    
    'assert.includes()': function(){
        assert.includes('some random string', 'dom');
        assert.throws(function(){
           assert.include('some random string', 'foobar');
        });
    
        assert.includes(['foo', 'bar'], 'bar');
        assert.includes(['foo', 'bar'], 'foo');
        assert.includes([1,2,3], 3);
        assert.includes([1,2,3], 2);
        assert.includes([1,2,3], 1);
        assert.throws(function(){
            assert.includes(['foo', 'bar'], 'baz');
        });
        
        assert.throws(function(){
            assert.includes({ wrong: 'type' }, 'foo');
        });
    },
    
    'assert.isNull()': function(){
        assert.isNull(null);
        assert.throws(function(){
            assert.isNull(undefined);
        });
        assert.throws(function(){
            assert.isNull(false);
        });
    },
    
    'assert.isUndefined()': function(){
        assert.isUndefined(undefined);
        assert.throws(function(){
            assert.isUndefined(null);
        });
        assert.throws(function(){
            assert.isUndefined(false);
        });
    },
    
    'assert.isNotNull()': function(){
        assert.isNotNull(false);
        assert.isNotNull(undefined);
        assert.throws(function(){
            assert.isNotNull(null);
        });
    },
    
    'assert.isDefined()': function(){
        assert.isDefined(false);
        assert.isDefined(null);
        assert.throws(function(){
            assert.isDefined(undefined);
        });
    },
    
    'assert.match()': function(){
        assert.match('foobar', /foo(bar)?/);
        assert.throws(function(){
            assert.match('something', /rawr/);
        });
    }
};