Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE beta] Assert key in Ember.get is not empty #14575

Merged
merged 1 commit into from
Nov 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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