zhangjian
2023-08-07 6b009b0f6d3ef3aee97c362cebcd679d1b9088a3
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
var is = require('../src/is');
 
describe('is', function() {
    before(function() {
        global.node = document.createElement('div');
        global.node.setAttribute('id', 'foo');
        global.node.setAttribute('class', 'foo');
        document.body.appendChild(global.node);
    });
 
    after(function() {
        document.body.innerHTML = '';
    });
 
    describe('is.node', function() {
        it('should be considered as node', function() {
            assert.ok(is.node(document.getElementById('foo')));
            assert.ok(is.node(document.getElementsByTagName('div')[0]));
            assert.ok(is.node(document.getElementsByClassName('foo')[0]));
            assert.ok(is.node(document.querySelector('.foo')));
        });
 
        it('should not be considered as node', function() {
            assert.notOk(is.node(undefined));
            assert.notOk(is.node(null));
            assert.notOk(is.node(false));
            assert.notOk(is.node(true));
            assert.notOk(is.node(function () {}));
            assert.notOk(is.node([]));
            assert.notOk(is.node({}));
            assert.notOk(is.node(/a/g));
            assert.notOk(is.node(new RegExp('a', 'g')));
            assert.notOk(is.node(new Date()));
            assert.notOk(is.node(42));
            assert.notOk(is.node(NaN));
            assert.notOk(is.node(Infinity));
            assert.notOk(is.node(new Number(42)));
        });
    });
 
    describe('is.nodeList', function() {
        it('should be considered as nodeList', function() {
            assert.ok(is.nodeList(document.getElementsByTagName('div')));
            assert.ok(is.nodeList(document.getElementsByClassName('foo')));
            assert.ok(is.nodeList(document.querySelectorAll('.foo')));
        });
 
        it('should not be considered as nodeList', function() {
            assert.notOk(is.nodeList(undefined));
            assert.notOk(is.nodeList(null));
            assert.notOk(is.nodeList(false));
            assert.notOk(is.nodeList(true));
            assert.notOk(is.nodeList(function () {}));
            assert.notOk(is.nodeList([]));
            assert.notOk(is.nodeList({}));
            assert.notOk(is.nodeList(/a/g));
            assert.notOk(is.nodeList(new RegExp('a', 'g')));
            assert.notOk(is.nodeList(new Date()));
            assert.notOk(is.nodeList(42));
            assert.notOk(is.nodeList(NaN));
            assert.notOk(is.nodeList(Infinity));
            assert.notOk(is.nodeList(new Number(42)));
        });
    });
 
    describe('is.string', function() {
        it('should be considered as string', function() {
            assert.ok(is.string('abc'));
            assert.ok(is.string(new String('abc')));
        });
 
        it('should not be considered as string', function() {
            assert.notOk(is.string(undefined));
            assert.notOk(is.string(null));
            assert.notOk(is.string(false));
            assert.notOk(is.string(true));
            assert.notOk(is.string(function () {}));
            assert.notOk(is.string([]));
            assert.notOk(is.string({}));
            assert.notOk(is.string(/a/g));
            assert.notOk(is.string(new RegExp('a', 'g')));
            assert.notOk(is.string(new Date()));
            assert.notOk(is.string(42));
            assert.notOk(is.string(NaN));
            assert.notOk(is.string(Infinity));
            assert.notOk(is.string(new Number(42)));
        });
    });
 
    describe('is.fn', function() {
        it('should be considered as function', function() {
            assert.ok(is.fn(function () {}));
        });
 
        it('should not be considered as function', function() {
            assert.notOk(is.fn(undefined));
            assert.notOk(is.fn(null));
            assert.notOk(is.fn(false));
            assert.notOk(is.fn(true));
            assert.notOk(is.fn([]));
            assert.notOk(is.fn({}));
            assert.notOk(is.fn(/a/g));
            assert.notOk(is.fn(new RegExp('a', 'g')));
            assert.notOk(is.fn(new Date()));
            assert.notOk(is.fn(42));
            assert.notOk(is.fn(NaN));
            assert.notOk(is.fn(Infinity));
            assert.notOk(is.fn(new Number(42)));
        });
    });
});