Skip to content

Commit

Permalink
Merge pull request #14575 from Serabe/feature/assert-key-not-empty
Browse files Browse the repository at this point in the history
[FEATURE beta] Assert key in `Ember.get` is not empty
  • Loading branch information
rwjblue authored Nov 4, 2016
2 parents d5acb2d + d03ff1f commit 43daba2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/ember-metal/lib/property_get.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export function get(obj, keyName) {
assert(`Cannot call get with '${keyName}' on an undefined object.`, obj !== undefined && obj !== null);
assert(`The key provided to get must be a string, you passed ${keyName}`, typeof keyName === 'string');
assert(`'this' in paths is not supported`, !hasThis(keyName));
assert('Cannot call `Ember.get` with an empty string', keyName !== '');

let value = obj[keyName];
let desc = (value !== null && typeof value === 'object' && value.isDescriptor) ? value : undefined;
Expand Down
9 changes: 1 addition & 8 deletions packages/ember-metal/tests/accessors/get_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ QUnit.test('should not access a property more than once', function() {
equal(count, 1);
});

QUnit.test('should be able to use an empty string as a property', function(assert) {
let obj = { '': 'empty string' };

let result = get(obj, '');

assert.equal(result, obj['']);
});

testBoth('should call unknownProperty on watched values if the value is undefined', function(get, set) {
let obj = {
count: 0,
Expand Down Expand Up @@ -114,6 +106,7 @@ QUnit.test('warn on attempts to use get with an unsupported property path', func
expectAssertion(() => get(obj, undefined), /The key provided to get must be a string, you passed undefined/);
expectAssertion(() => get(obj, false), /The key provided to get must be a string, you passed false/);
expectAssertion(() => get(obj, 42), /The key provided to get must be a string, you passed 42/);
expectAssertion(() => get(obj, ''), /Cannot call `Ember.get` with an empty string/);
});

// ..........................................................
Expand Down

0 comments on commit 43daba2

Please sign in to comment.