1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | Object.defineProperty(exports, "__esModule", { value: true });
|
19 | const assert = require("assert");
|
20 | const mocha_1 = require("mocha");
|
21 | const index_1 = require("../index");
|
22 | mocha_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 |
|
\ | No newline at end of file |