1 |
|
2 | const assert = require('assert');
|
3 | const { isNumber, isObject, isNil, getFuncName } = require('../types');
|
4 |
|
5 | describe('Types', function() {
|
6 | describe('#isNumber()', function() {
|
7 | it('should return false for undefined types', function() {
|
8 | assert.strictEqual(isNumber(), false);
|
9 | assert.strictEqual(isNumber(null), false);
|
10 | assert.strictEqual(isNumber(undefined), false);
|
11 | });
|
12 | it('should return true for any kind of number', function() {
|
13 | assert.strictEqual(isNumber('1'), true);
|
14 | assert.strictEqual(isNumber(4), true);
|
15 | assert.strictEqual(isNumber('1.65'), true);
|
16 | assert.strictEqual(isNumber('0b0001'), true);
|
17 | });
|
18 | it('should return false for any kind of string', function() {
|
19 | assert.strictEqual(isNumber('1x'), false);
|
20 | assert.strictEqual(isNumber('x11'), false);
|
21 | });
|
22 | });
|
23 | describe('#isObject()', function() {
|
24 | it('should return false for undefined types', function() {
|
25 | assert.strictEqual(isObject(), false);
|
26 | assert.strictEqual(isObject(null), false);
|
27 | assert.strictEqual(isObject(undefined), false);
|
28 | });
|
29 | it('should return true for objects', function() {
|
30 | assert.strictEqual(isObject({}), true);
|
31 | assert.strictEqual(isObject({ a: 1 }), true);
|
32 | });
|
33 | it('should return true for instances', function() {
|
34 | assert.strictEqual(isObject(new Error('hello')), true);
|
35 | });
|
36 | });
|
37 | describe('#isNil()', function() {
|
38 | it('should true for undefined', function() {
|
39 | assert.strictEqual(isNil(), true);
|
40 | });
|
41 | it('should true for null', function() {
|
42 | assert.strictEqual(isNil(null), true);
|
43 | });
|
44 | it('should false for any existent type', function() {
|
45 | assert.strictEqual(isNil(0), false);
|
46 | assert.strictEqual(isNil(''), false);
|
47 | assert.strictEqual(isNil(1.234), false);
|
48 | assert.strictEqual(isNil({}), false);
|
49 | assert.strictEqual(isNil([]), false);
|
50 | });
|
51 | });
|
52 | describe('#getFuncName()', function() {
|
53 | it('should return Unknown if called outside a function', function() {
|
54 | assert.strictEqual(getFuncName(), 'Unknown');
|
55 | });
|
56 | it('should return the passed value if called outside a function', function() {
|
57 | assert.strictEqual(getFuncName('ups'), 'ups');
|
58 | });
|
59 | it('should return the name of the arrow function that called ', function() {
|
60 | const hellow = () => getFuncName();
|
61 | assert.strictEqual(hellow(), 'hellow');
|
62 | });
|
63 | it('should return the name of the regular function that called ', function() {
|
64 | function hellow() {
|
65 | return getFuncName();
|
66 | }
|
67 | assert.strictEqual(hellow(), 'hellow');
|
68 | });
|
69 | });
|
70 | });
|