Debian Codegraph @

good-listener/test/is.js

raw
1 var is = require('../src/is');
2
3 describe('is', function() {
4 before(function() {
5 global.node = document.createElement('div');
6 global.node.setAttribute('id', 'foo');
7 global.node.setAttribute('class', 'foo');
8 document.body.appendChild(global.node);
9 });
10
11 after(function() {
12 document.body.innerHTML = '';
13 });
14
15 describe('is.node', function() {
16 it('should be considered as node', function() {
17 assert.ok(is.node(document.getElementById('foo')));
18 assert.ok(is.node(document.getElementsByTagName('div')[0]));
19 assert.ok(is.node(document.getElementsByClassName('foo')[0]));
20 assert.ok(is.node(document.querySelector('.foo')));
21 });
22
23 it('should not be considered as node', function() {
24 assert.notOk(is.node(undefined));
25 assert.notOk(is.node(null));
26 assert.notOk(is.node(false));
27 assert.notOk(is.node(true));
28 assert.notOk(is.node(function () {}));
29 assert.notOk(is.node([]));
30 assert.notOk(is.node({}));
31 assert.notOk(is.node(/a/g));
32 assert.notOk(is.node(new RegExp('a', 'g')));
33 assert.notOk(is.node(new Date()));
34 assert.notOk(is.node(42));
35 assert.notOk(is.node(NaN));
36 assert.notOk(is.node(Infinity));
37 assert.notOk(is.node(new Number(42)));
38 });
39 });
40
41 describe('is.nodeList', function() {
42 it('should be considered as nodeList', function() {
43 assert.ok(is.nodeList(document.getElementsByTagName('div')));
44 assert.ok(is.nodeList(document.getElementsByClassName('foo')));
45 assert.ok(is.nodeList(document.querySelectorAll('.foo')));
46 });
47
48 it('should not be considered as nodeList', function() {
49 assert.notOk(is.nodeList(undefined));
50 assert.notOk(is.nodeList(null));
51 assert.notOk(is.nodeList(false));
52 assert.notOk(is.nodeList(true));
53 assert.notOk(is.nodeList(function () {}));
54 assert.notOk(is.nodeList([]));
55 assert.notOk(is.nodeList({}));
56 assert.notOk(is.nodeList(/a/g));
57 assert.notOk(is.nodeList(new RegExp('a', 'g')));
58 assert.notOk(is.nodeList(new Date()));
59 assert.notOk(is.nodeList(42));
60 assert.notOk(is.nodeList(NaN));
61 assert.notOk(is.nodeList(Infinity));
62 assert.notOk(is.nodeList(new Number(42)));
63 });
64 });
65
66 describe('is.string', function() {
67 it('should be considered as string', function() {
68 assert.ok(is.string('abc'));
69 assert.ok(is.string(new String('abc')));
70 });
71
72 it('should not be considered as string', function() {
73 assert.notOk(is.string(undefined));
74 assert.notOk(is.string(null));
75 assert.notOk(is.string(false));
76 assert.notOk(is.string(true));
77 assert.notOk(is.string(function () {}));
78 assert.notOk(is.string([]));
79 assert.notOk(is.string({}));
80 assert.notOk(is.string(/a/g));
81 assert.notOk(is.string(new RegExp('a', 'g')));
82 assert.notOk(is.string(new Date()));
83 assert.notOk(is.string(42));
84 assert.notOk(is.string(NaN));
85 assert.notOk(is.string(Infinity));
86 assert.notOk(is.string(new Number(42)));
87 });
88 });
89
90 describe('is.fn', function() {
91 it('should be considered as function', function() {
92 assert.ok(is.fn(function () {}));
93 });
94
95 it('should not be considered as function', function() {
96 assert.notOk(is.fn(undefined));
97 assert.notOk(is.fn(null));
98 assert.notOk(is.fn(false));
99 assert.notOk(is.fn(true));
100 assert.notOk(is.fn([]));
101 assert.notOk(is.fn({}));
102 assert.notOk(is.fn(/a/g));
103 assert.notOk(is.fn(new RegExp('a', 'g')));
104 assert.notOk(is.fn(new Date()));
105 assert.notOk(is.fn(42));
106 assert.notOk(is.fn(NaN));
107 assert.notOk(is.fn(Infinity));
108 assert.notOk(is.fn(new Number(42)));
109 });
110 });
111 });