UNPKG

4.74 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2022 Ericsson and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16// *****************************************************************************
17Object.defineProperty(exports, "__esModule", { value: true });
18const chai_1 = require("chai");
19const objects_1 = require("./objects");
20describe('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 // eslint-disable-next-line no-null/no-null
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//# sourceMappingURL=objects.spec.js.map
\No newline at end of file