Sha256: 2758d3b42490714b1d75b3492c56098511422d23d709f778b9fddcb6c2a349d8

Contents?: true

Size: 1.64 KB

Versions: 3

Compression:

Stored size: 1.64 KB

Contents

import { A as emberA } from '../../lib/mixins/array';
import { AbstractTestCase } from 'internal-test-helpers';
import { runArrayTests } from '../helpers/array';

class AnyTests extends AbstractTestCase {
  '@test any should should invoke callback on each item as long as you return false'() {
    let obj = this.newObject();
    let ary = this.toArray(obj);
    let found = [];
    let result;

    result = obj.any(function(i) {
      found.push(i);
      return false;
    });

    this.assert.equal(result, false, 'return value of obj.any');
    this.assert.deepEqual(found, ary, 'items passed during any() should match');
  }

  '@test any should stop invoking when you return true'() {
    let obj = this.newObject();
    let ary = this.toArray(obj);
    let cnt = ary.length - 2;
    let exp = cnt;
    let found = [];
    let result;

    result = obj.any(function(i) {
      found.push(i);
      return --cnt <= 0;
    });
    this.assert.equal(result, true, 'return value of obj.any');
    this.assert.equal(found.length, exp, 'should invoke proper number of times');
    this.assert.deepEqual(found, ary.slice(0, -2), 'items passed during any() should match');
  }

  '@test any should return true if any object matches the callback'() {
    let obj = emberA([0, 1, 2]);
    let result;

    result = obj.any(i => !!i);
    this.assert.equal(result, true, 'return value of obj.any');
  }

  '@test any should produce correct results even if the matching element is undefined'(assert) {
    let obj = emberA([undefined]);
    let result;

    result = obj.any(() => true);
    assert.equal(result, true, 'return value of obj.any');
  }
}

runArrayTests('any', AnyTests);

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
discourse-ember-source-3.6.0.0 dist/es/@ember/-internals/runtime/tests/array/any-test.js
discourse-ember-source-3.5.1.1 dist/es/ember-runtime/tests/array/any-test.js
discourse-ember-source-3.5.1.0 dist/dist/es/ember-runtime/tests/array/any-test.js