UNPKG

nope-js-node

Version:

NoPE Runtime for Nodejs. For Browser-Support please use nope-browser

92 lines (91 loc) 4.04 kB
"use strict"; /** * @author Martin Karkowski * @email m.karkowski@zema.de * @desc [description] */ Object.defineProperty(exports, "__esModule", { value: true }); const chai_1 = require("chai"); const mocha_1 = require("mocha"); const mapMethods_1 = require("./mapMethods"); (0, mocha_1.describe)("mapMethods", function () { // Describe the required Test: (0, mocha_1.describe)("extractUniqueValues", function () { (0, mocha_1.it)("simple-map", function () { const m = new Map(); m.set("a", "b"); m.set("b", "b"); const result = (0, mapMethods_1.extractUniqueValues)(m); chai_1.assert.isTrue(result.size === 1, "Elements have the same identity, but should be differend"); chai_1.assert.isTrue([...result][0] === "b", "Element is element"); }); (0, mocha_1.it)("nested-map", function () { const m = new Map(); m.set("a", { a: "b" }); m.set("b", { a: "b" }); const result = (0, mapMethods_1.extractUniqueValues)(m, "a"); chai_1.assert.isTrue(result.size === 1, "Elements have the same identity, but should be differend"); chai_1.assert.isTrue([...result][0] === "b", "Element is element"); }); (0, mocha_1.it)("nested-array", function () { const m = new Map(); m.set("a", { a: ["b"] }); m.set("b", { a: ["b"] }); m.set("b", { b: ["b"] }); m.set("b", { a: ["c"] }); const result = (0, mapMethods_1.extractUniqueValues)(m, "a/+"); chai_1.assert.isTrue(result.size === 2, "Elements have the same identity, but should be differend"); const r = [...result].sort(); chai_1.assert.isTrue(r[0] === "b", "Element is element"); }); (0, mocha_1.it)("flat-array", function () { const m = new Map(); m.set("a", ["a"]); m.set("b", ["a", "b"]); const result = (0, mapMethods_1.extractUniqueValues)(m, "+"); (0, chai_1.expect)(result.size).to.equal(2); chai_1.assert.isTrue(result.size === 2, "The Element should include 2 elements. namely 'a' and 'b'"); chai_1.assert.isArray([...result], "Should be an array"); (0, chai_1.expect)([...result]).to.contain("a"); (0, chai_1.expect)([...result]).to.contain("b"); }); (0, mocha_1.it)("nested-array multiple elements", function () { const m = new Map(); m.set("a", { a: ["b"] }); m.set("b", { a: ["c", "d"] }); const result = (0, mapMethods_1.extractUniqueValues)(m, "a/+"); chai_1.assert.isTrue(result.size === 3, "Elements have the same identity, but should be differend"); chai_1.assert.deepEqual(["b", "c", "d"], [...result], "Items are missing"); }); (0, mocha_1.it)("nested-object, different key", function () { const m = new Map(); m.set("a", { a: [ { content: "a", id: 1, }, { content: "b", id: 2, }, ], }); m.set("b", { a: [ { content: "c", id: 1, }, { content: "d", id: 3, }, ], }); const result = (0, mapMethods_1.extractUniqueValues)(m, "a/+/content", "a/+/id"); chai_1.assert.isTrue(result.size === 3, "Elements have the same identity, but should be differend"); chai_1.assert.deepEqual(["a", "b", "d"], [...result], "Items are missing"); }); }); });