diff --git a/packages/ember-utils/lib/invoke.js b/packages/ember-utils/lib/invoke.js index e708b81d854..688be948b24 100644 --- a/packages/ember-utils/lib/invoke.js +++ b/packages/ember-utils/lib/invoke.js @@ -19,7 +19,7 @@ import applyStr from './apply-str'; @private */ export function canInvoke(obj, methodName) { - return !!(obj && typeof obj[methodName] === 'function'); + return obj !== null && obj !== undefined && typeof obj[methodName] === 'function'; } /** diff --git a/packages/ember-utils/tests/can_invoke_test.js b/packages/ember-utils/tests/can_invoke_test.js index 5dc7ba9be49..a3974a1c99d 100644 --- a/packages/ember-utils/tests/can_invoke_test.js +++ b/packages/ember-utils/tests/can_invoke_test.js @@ -19,6 +19,12 @@ QUnit.test('should return false if the object doesn\'t exist', function() { equal(canInvoke(undefined, 'aMethodThatDoesNotExist'), false); }); +QUnit.test('should return true for falsy values that have methods', function() { + equal(canInvoke(false, 'valueOf'), true); + equal(canInvoke('', 'charAt'), true); + equal(canInvoke(0, 'toFixed'), true); +}); + QUnit.test('should return true if the method exists on the object', function() { equal(canInvoke(obj, 'aMethodThatExists'), true); });