1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | const chai_1 = require("chai");
|
19 | const objects_1 = require("./objects");
|
20 | describe('Objects', () => {
|
21 | describe('#deepClone', () => {
|
22 | describe('primitives', () => {
|
23 | it('should deep clone numbers', () => {
|
24 | (0, chai_1.expect)(1).to.equal((0, objects_1.deepClone)(1));
|
25 | });
|
26 | it('should deep clone strings', () => {
|
27 | (0, chai_1.expect)('foo').to.equal((0, objects_1.deepClone)('foo'));
|
28 | (0, chai_1.expect)('').to.equal((0, objects_1.deepClone)(''));
|
29 | });
|
30 | it('should deep clone booleans', () => {
|
31 | (0, chai_1.expect)(true).to.equal((0, objects_1.deepClone)(true));
|
32 | (0, chai_1.expect)(false).to.equal((0, objects_1.deepClone)(false));
|
33 | });
|
34 | });
|
35 | describe('undefined', () => {
|
36 | it('should deep clone undefined', () => {
|
37 | (0, chai_1.expect)(undefined).to.equal((0, objects_1.deepClone)(undefined));
|
38 | });
|
39 | });
|
40 | describe('arrays', () => {
|
41 | it('should deep clone arrays', () => {
|
42 | const a = [1, 2, 3];
|
43 | const b = (0, objects_1.deepClone)(a);
|
44 | (0, chai_1.expect)(a).to.deep.equal(b);
|
45 | (0, chai_1.expect)(Array.isArray(a)).to.equal(true);
|
46 | (0, chai_1.expect)(Array.isArray(b)).to.equal(true);
|
47 | });
|
48 | it('should deep clone nested arrays', () => {
|
49 | const a = [[1], [2]];
|
50 | const b = (0, objects_1.deepClone)(a);
|
51 | (0, chai_1.expect)(a).to.deep.equal(b);
|
52 | (0, chai_1.expect)(Array.isArray(a)).to.equal(true);
|
53 | (0, chai_1.expect)(Array.isArray(b)).to.equal(true);
|
54 | });
|
55 | });
|
56 | describe('objects', () => {
|
57 | it('should deep clone objects', () => {
|
58 | const a = { 'foo': true, 'bar': 1 };
|
59 | const b = (0, objects_1.deepClone)(a);
|
60 | (0, chai_1.expect)(a).to.deep.equal(b);
|
61 | (0, chai_1.expect)(typeof a).to.equal('object');
|
62 | (0, chai_1.expect)(typeof b).to.equal('object');
|
63 | });
|
64 | it('should deep clone nested objects', () => {
|
65 | const a = { 'foo': true, 'nested': { 'foo': 1 } };
|
66 | const b = (0, objects_1.deepClone)(a);
|
67 | (0, chai_1.expect)(a).to.deep.equal(b);
|
68 | (0, chai_1.expect)(typeof a).to.equal('object');
|
69 | (0, chai_1.expect)(typeof b).to.equal('object');
|
70 | });
|
71 | });
|
72 | });
|
73 | describe('#deepFreeze', () => {
|
74 | it('should deep freeze an object', () => {
|
75 | const e = { a: 10 };
|
76 | const d = (0, objects_1.deepFreeze)(e);
|
77 | (0, chai_1.expect)(Object.isFrozen(d)).to.equal(true);
|
78 | });
|
79 | });
|
80 | describe('#notEmpty', () => {
|
81 | it('should return "true" when not empty', () => {
|
82 | (0, chai_1.expect)((0, objects_1.notEmpty)({})).to.equal(true);
|
83 | (0, chai_1.expect)((0, objects_1.notEmpty)([])).to.equal(true);
|
84 | (0, chai_1.expect)((0, objects_1.notEmpty)({ a: 1 })).to.equal(true);
|
85 | });
|
86 | it('should return "false" when empty', () => {
|
87 | (0, chai_1.expect)((0, objects_1.notEmpty)(undefined)).to.equal(false);
|
88 | });
|
89 | });
|
90 | describe('#isEmpty', () => {
|
91 | it('should return "true" when it is empty', () => {
|
92 |
|
93 | const obj = Object.create(null);
|
94 | (0, chai_1.expect)((0, objects_1.isEmpty)(obj)).to.equal(false);
|
95 | });
|
96 | it('should return "false" when not empty', () => {
|
97 | const z = { d: 5 };
|
98 | (0, chai_1.expect)((0, objects_1.isEmpty)(z)).to.equal(false);
|
99 | });
|
100 | });
|
101 | });
|
102 |
|
\ | No newline at end of file |