Skip to content

Commit

Permalink
added tests for get with paths
Browse files Browse the repository at this point in the history
  • Loading branch information
bekzod committed Jun 7, 2018
1 parent f7be3c7 commit 1e9796d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/ember-metal/tests/accessors/get_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ENV } from 'ember-environment';
import { Object as EmberObject } from 'ember-runtime';
import { get, getWithDefault, Mixin, observer, computed } from '../..';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
import { run } from '@ember/runloop';

function aget(x, y) {
return x[y];
Expand Down Expand Up @@ -98,6 +100,23 @@ moduleFor(
}
}

["@test get works with paths correctly"](assert) {
let func = function() {};
func.bar = 'awesome';

let destroyedObj = EmberObject.create({ bar: 'great' });
run(() => destroyedObj.destroy());

assert.equal(get({ foo: null }, 'foo.bar'), undefined);
assert.equal(get({ foo: { bar: 'hello' } }, 'foo.bar.length'), 5);
assert.equal(get({ foo: func }, 'foo.bar'), 'awesome');
assert.equal(get({ foo: func }, 'foo.bar.length'), 7);
assert.equal(get({}, 'foo.bar.length'), undefined);
assert.equal(get(function(){}, 'foo.bar.length'), undefined);
assert.equal(get('', 'foo.bar.length'), undefined);
assert.equal(get({ foo: destroyedObj }, 'foo.bar'), undefined);
}

['@test warn on attempts to call get with no arguments']() {
expectAssertion(function() {
get('aProperty');
Expand Down

0 comments on commit 1e9796d

Please sign in to comment.