diff --git a/addon/helpers/invoke.js b/addon/helpers/invoke.js index a78a4ca0..d05c9ce0 100644 --- a/addon/helpers/invoke.js +++ b/addon/helpers/invoke.js @@ -1,6 +1,5 @@ import { isArray as isEmberArray } from '@ember/array'; import { helper } from '@ember/component/helper'; -import { tryInvoke } from '@ember/utils'; import RSVP from 'rsvp'; const { all } = RSVP; @@ -10,14 +9,14 @@ export function invoke([methodName, ...args]) { if (isEmberArray(obj)) { return function() { - let promises = obj.map((item) => tryInvoke(item, methodName, args)); + let promises = obj.map((item) => item[methodName]?.(...args)); return all(promises); }; } return function() { - return tryInvoke(obj, methodName, args); + return obj[methodName]?.(...args); }; } diff --git a/tests/unit/helpers/invoke-test.js b/tests/unit/helpers/invoke-test.js index 7647d250..5cc934fb 100644 --- a/tests/unit/helpers/invoke-test.js +++ b/tests/unit/helpers/invoke-test.js @@ -15,6 +15,17 @@ module('Unit | Helper | invoke', function() { assert.equal(action(), 'calling mom in 1,2,3', 'it calls functions'); }); + test('it cares about method arguments', function(assert) { + let object = { + callContact(name, number) { + return `calling ${name} with ${number}`; + } + }; + let action = invoke(['callContact', 'mom', '1234567', object]); + + assert.equal(action(), 'calling mom with 1234567', 'it cares about function args'); + }); + test('it is promise aware', function(assert) { let done = assert.async(); let object = {