Sha256: 91a85c00aefb2b3c753314c8f627247db58332355db68a21064f92377ffb11e8

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

import { tryInvoke } from '..';
import { moduleFor, AbstractTestCase as TestCase } from 'internal-test-helpers';

let obj;

moduleFor(
  'Ember.tryInvoke',
  class extends TestCase {
    constructor() {
      super();

      obj = {
        aMethodThatExists() {
          return true;
        },
        aMethodThatTakesArguments(arg1, arg2) {
          return arg1 === arg2;
        },
      };
    }

    teardown() {
      obj = undefined;
    }

    ["@test should return undefined when the object doesn't exist"](assert) {
      assert.equal(tryInvoke(undefined, 'aMethodThatDoesNotExist'), undefined);
    }

    ["@test should return undefined when asked to perform a method that doesn't exist on the object"](
      assert
    ) {
      assert.equal(tryInvoke(obj, 'aMethodThatDoesNotExist'), undefined);
    }

    ['@test should return what the method returns when asked to perform a method that exists on the object'](
      assert
    ) {
      assert.equal(tryInvoke(obj, 'aMethodThatExists'), true);
    }

    ['@test should return what the method returns when asked to perform a method that takes arguments and exists on the object'](
      assert
    ) {
      assert.equal(tryInvoke(obj, 'aMethodThatTakesArguments', [true, true]), true);
    }
  }
);

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
discourse-ember-source-3.6.0.0 dist/es/@ember/-internals/utils/tests/try_invoke_test.js
discourse-ember-source-3.5.1.1 dist/es/ember-utils/tests/try_invoke_test.js
discourse-ember-source-3.5.1.0 dist/dist/es/ember-utils/tests/try_invoke_test.js