UNPKG

3.46 kBJavaScriptView Raw
1"use strict";
2/**
3 * This file is part of the @egodigital/egoose distribution.
4 * Copyright (c) e.GO Digital GmbH, Aachen, Germany (https://www.e-go-digital.com/)
5 *
6 * @egodigital/egoose is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation, version 3.
9 *
10 * @egodigital/egoose is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18Object.defineProperty(exports, "__esModule", { value: true });
19const assert = require("assert");
20const mocha_1 = require("mocha");
21const index_1 = require("../index");
22mocha_1.describe('#applyFuncFor()', function () {
23 mocha_1.describe('(null)', function () {
24 mocha_1.it('should use OBJ_2 as thisArg instead of OBJ_1 (sync)', function () {
25 let objOfFunc;
26 const OBJ_1 = {
27 test: function (a, b) {
28 objOfFunc = this;
29 return a + b;
30 },
31 };
32 const OBJ_2 = {};
33 const FUNC = index_1.applyFuncFor(OBJ_1.test, OBJ_2);
34 assert.ok('function' === typeof FUNC);
35 assert.notEqual(FUNC, OBJ_1.test);
36 assert.notStrictEqual(FUNC, OBJ_1.test);
37 for (let a = 0; a < 100; a++) {
38 for (let b = 0; b < 100; b++) {
39 objOfFunc = false;
40 const EXPECTED_SUM = a + b;
41 const ACTUAL_SUM = FUNC(a, b);
42 assert.ok('number' === typeof ACTUAL_SUM);
43 assert.equal(ACTUAL_SUM, EXPECTED_SUM);
44 assert.strictEqual(ACTUAL_SUM, EXPECTED_SUM);
45 assert.ok('object' === typeof objOfFunc);
46 assert.equal(objOfFunc, OBJ_2);
47 assert.strictEqual(objOfFunc, OBJ_2);
48 }
49 }
50 });
51 mocha_1.it('should use OBJ_2 as thisArg instead of OBJ_1 (async)', async function () {
52 let objOfFunc;
53 const OBJ_1 = {
54 test: async function (a, b) {
55 objOfFunc = this;
56 return a + b;
57 },
58 };
59 const OBJ_2 = {};
60 const FUNC = index_1.applyFuncFor(OBJ_1.test, OBJ_2);
61 assert.ok('function' === typeof FUNC);
62 assert.notEqual(FUNC, OBJ_1.test);
63 assert.notStrictEqual(FUNC, OBJ_1.test);
64 for (let a = 0; a < 100; a++) {
65 for (let b = 0; b < 100; b++) {
66 objOfFunc = false;
67 const EXPECTED_SUM = a + b;
68 const ACTUAL_SUM = await FUNC(a, b);
69 assert.ok('number' === typeof ACTUAL_SUM);
70 assert.equal(ACTUAL_SUM, EXPECTED_SUM);
71 assert.strictEqual(ACTUAL_SUM, EXPECTED_SUM);
72 assert.ok('object' === typeof objOfFunc);
73 assert.equal(objOfFunc, OBJ_2);
74 assert.strictEqual(objOfFunc, OBJ_2);
75 }
76 }
77 });
78 });
79});
80//# sourceMappingURL=applyFuncFor.js.map
\No newline at end of file