import EmberObject from '../../lib/system/object';
import { AbstractTestCase } from 'internal-test-helpers';
import { runArrayTests } from '../helpers/array';

class InvokeTests extends AbstractTestCase {
  '@test invoke should call on each object that implements'() {
    let cnt, ary, obj;

    function F(amt) {
      cnt += amt === undefined ? 1 : amt;
    }
    cnt = 0;
    ary = [
      { foo: F },
      EmberObject.create({ foo: F }),

      // NOTE: does not impl foo - invoke should just skip
      EmberObject.create({ bar: F }),

      { foo: F },
    ];

    obj = this.newObject(ary);
    obj.invoke('foo');
    this.assert.equal(cnt, 3, 'should have invoked 3 times');

    cnt = 0;
    obj.invoke('foo', 2);
    this.assert.equal(cnt, 6, 'should have invoked 3 times, passing param');
  }
}

runArrayTests('invoke', InvokeTests);

@@ -4,49 +4,64 @@
 ort 
-EmberObject from '../../lib/system/object
+%7B Object as EmberObject, NativeArray %7D from '../../index
 ';%0Ai
@@ -813,16 +813,691 @@
 m');%0A  %7D
+%0A%0A  '@test invoke should return an array containing the results of each invoked method'(assert) %7B%0A    let obj = this.newObject(%5B%0A      %7B%0A        foo() %7B%0A          return 'one';%0A        %7D,%0A      %7D,%0A      %7B%7D, // intentionally not including %60foo%60 method%0A      %7B%0A        foo() %7B%0A          return 'two';%0A        %7D,%0A      %7D,%0A    %5D);%0A%0A    let result = obj.invoke('foo');%0A    assert.deepEqual(result, %5B'one', undefined, 'two'%5D);%0A  %7D%0A%0A  '@test invoke should return an extended array (aka Ember.A)'(assert) %7B%0A    let obj = this.newObject(%5B%7B foo() %7B%7D %7D, %7B foo() %7B%7D %7D%5D);%0A%0A    let result = obj.invoke('foo');%0A%0A    assert.ok(NativeArray.detect(result), 'NativeArray has been applied');%0A  %7D
 %0A%7D%0A%0ArunA

Add failing tests for `A().invoke()` not returning an `A`.