aboutsummaryrefslogtreecommitdiff
path: root/tools/addon-sdk-1.3/packages/api-utils/tests/test-function-utils.js
blob: 292380a87d67058ac675a780dd8ed3d41d2647b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const { invoke, Enqueued } = require('utils/function');

exports['test forwardApply'] = function(test) {
  function sum(b, c) this.a + b + c
  test.assertEqual(invoke(sum, [2, 3], { a: 1 }), 6,
                   'passed arguments and pseoude-variable are used');
  test.assertEqual(invoke(sum.bind({ a: 2 }), [2, 3], { a: 1 }), 7,
                   'bounded `this` pseoudo variable is used')
}

exports['test enqueued function'] = function(test) {
  test.waitUntilDone();
  let nextTurn = false;
  function sum(b, c) {
    test.assert(nextTurn, 'enqueued is called in next turn of event loop');
    test.assertEqual(this.a + b + c, 6,
                     'passed arguments an pseoude-variable are used');
    test.done();
  }
  let fixture = { a: 1, method: Enqueued(sum) }
  fixture.method(2, 3);
  nextTurn = true;
}