UNPKG

@egodigital/egoose

Version:

Helper classes and functions for Node.js 10 or later.

80 lines 3.46 kB
"use strict"; /** * This file is part of the @egodigital/egoose distribution. * Copyright (c) e.GO Digital GmbH, Aachen, Germany (https://www.e-go-digital.com/) * * @egodigital/egoose is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, version 3. * * @egodigital/egoose is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ Object.defineProperty(exports, "__esModule", { value: true }); const assert = require("assert"); const mocha_1 = require("mocha"); const index_1 = require("../index"); mocha_1.describe('#applyFuncFor()', function () { mocha_1.describe('(null)', function () { mocha_1.it('should use OBJ_2 as thisArg instead of OBJ_1 (sync)', function () { let objOfFunc; const OBJ_1 = { test: function (a, b) { objOfFunc = this; return a + b; }, }; const OBJ_2 = {}; const FUNC = index_1.applyFuncFor(OBJ_1.test, OBJ_2); assert.ok('function' === typeof FUNC); assert.notEqual(FUNC, OBJ_1.test); assert.notStrictEqual(FUNC, OBJ_1.test); for (let a = 0; a < 100; a++) { for (let b = 0; b < 100; b++) { objOfFunc = false; const EXPECTED_SUM = a + b; const ACTUAL_SUM = FUNC(a, b); assert.ok('number' === typeof ACTUAL_SUM); assert.equal(ACTUAL_SUM, EXPECTED_SUM); assert.strictEqual(ACTUAL_SUM, EXPECTED_SUM); assert.ok('object' === typeof objOfFunc); assert.equal(objOfFunc, OBJ_2); assert.strictEqual(objOfFunc, OBJ_2); } } }); mocha_1.it('should use OBJ_2 as thisArg instead of OBJ_1 (async)', async function () { let objOfFunc; const OBJ_1 = { test: async function (a, b) { objOfFunc = this; return a + b; }, }; const OBJ_2 = {}; const FUNC = index_1.applyFuncFor(OBJ_1.test, OBJ_2); assert.ok('function' === typeof FUNC); assert.notEqual(FUNC, OBJ_1.test); assert.notStrictEqual(FUNC, OBJ_1.test); for (let a = 0; a < 100; a++) { for (let b = 0; b < 100; b++) { objOfFunc = false; const EXPECTED_SUM = a + b; const ACTUAL_SUM = await FUNC(a, b); assert.ok('number' === typeof ACTUAL_SUM); assert.equal(ACTUAL_SUM, EXPECTED_SUM); assert.strictEqual(ACTUAL_SUM, EXPECTED_SUM); assert.ok('object' === typeof objOfFunc); assert.equal(objOfFunc, OBJ_2); assert.strictEqual(objOfFunc, OBJ_2); } } }); }); }); //# sourceMappingURL=applyFuncFor.js.map