Sha256: ea7be1819f0a537376316bb56edef9d4eab70e74390ab483f83a43e93f1815a7

Contents?: true

Size: 1.99 KB

Versions: 3

Compression:

Stored size: 1.99 KB

Contents

import { get } from '../..';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

let obj;

moduleFor(
  'get with path',
  class extends AbstractTestCase {
    constructor() {
      super();
      obj = {
        foo: {
          bar: {
            baz: { biff: 'BIFF' },
          },
        },
        foothis: {
          bar: {
            baz: { biff: 'BIFF' },
          },
        },
        falseValue: false,
        emptyString: '',
        Wuz: {
          nar: 'foo',
        },
        nullValue: null,
      };
    }

    teardown() {
      obj = undefined;
    }

    // ..........................................................
    // LOCAL PATHS
    //
    ['@test [obj, foo] -> obj.foo'](assert) {
      assert.deepEqual(get(obj, 'foo'), obj.foo);
    }

    ['@test [obj, foo.bar] -> obj.foo.bar'](assert) {
      assert.deepEqual(get(obj, 'foo.bar'), obj.foo.bar);
    }

    ['@test [obj, foothis.bar] -> obj.foothis.bar'](assert) {
      assert.deepEqual(get(obj, 'foothis.bar'), obj.foothis.bar);
    }

    ['@test [obj, falseValue.notDefined] -> (undefined)'](assert) {
      assert.strictEqual(get(obj, 'falseValue.notDefined'), undefined);
    }

    ['@test [obj, emptyString.length] -> 0'](assert) {
      assert.strictEqual(get(obj, 'emptyString.length'), 0);
    }

    ['@test [obj, nullValue.notDefined] -> (undefined)'](assert) {
      assert.strictEqual(get(obj, 'nullValue.notDefined'), undefined);
    }

    // ..........................................................
    // GLOBAL PATHS TREATED LOCAL WITH GET
    //

    ['@test [obj, Wuz] -> obj.Wuz'](assert) {
      assert.deepEqual(get(obj, 'Wuz'), obj.Wuz);
    }

    ['@test [obj, Wuz.nar] -> obj.Wuz.nar'](assert) {
      assert.deepEqual(get(obj, 'Wuz.nar'), obj.Wuz.nar);
    }

    ['@test [obj, Foo] -> (undefined)'](assert) {
      assert.strictEqual(get(obj, 'Foo'), undefined);
    }

    ['@test [obj, Foo.bar] -> (undefined)'](assert) {
      assert.strictEqual(get(obj, 'Foo.bar'), undefined);
    }
  }
);

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
discourse-ember-source-3.6.0.0 dist/es/@ember/-internals/metal/tests/accessors/get_path_test.js
discourse-ember-source-3.5.1.1 dist/es/ember-metal/tests/accessors/get_path_test.js
discourse-ember-source-3.5.1.0 dist/dist/es/ember-metal/tests/accessors/get_path_test.js