Skip to content

Commit

Permalink
Merge pull request #16870 from nlfurniss/let-get-empty-string
Browse files Browse the repository at this point in the history
[BUGFIX beta] Enable @ember/object#get to be called with an empty string
  • Loading branch information
rwjblue committed Aug 8, 2018
2 parents ddec402 + ad64f82 commit 223dc58
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
16 changes: 16 additions & 0 deletions packages/ember-glimmer/tests/integration/syntax/each-in-test.js
Expand Up @@ -281,6 +281,22 @@ class EachInTest extends AbstractEachInTest {

this.assertText('Empty!');
}

[`@test it can render items with a key of empty string`]() {
this.makeHash({ '': 'empty-string', a: 'a' });

this.render(
`<ul>{{#each-in hash as |key value|}}<li>{{key}}: {{value}}</li>{{else}}Empty!{{/each-in}}</ul>`
);

this.assertText(': empty-stringa: a');

this.assertStableRerender();

this.clear();

this.assertText('Empty!');
}
}

moduleFor(
Expand Down
1 change: 0 additions & 1 deletion packages/ember-metal/lib/property_get.ts
Expand Up @@ -90,7 +90,6 @@ export function get(obj: object, keyName: string): any {
`'this' in paths is not supported`,
typeof keyName !== 'string' || keyName.lastIndexOf('this.', 0) !== 0
);
assert('Cannot call `get` with an empty string', keyName !== '');

let type = typeof obj;

Expand Down
15 changes: 14 additions & 1 deletion packages/ember-metal/tests/accessors/get_test.js
Expand Up @@ -59,6 +59,20 @@ moduleFor(
assert.equal(get(arr, 1), 'second');
}

['@test should retrieve an empty string key on an object'](assert) {
let obj = { '': 'empty-string' };

assert.equal(get(obj, ''), 'empty-string');
}

['@test should return undefined when passed an empty string if that key does not exist on an object'](
assert
) {
let obj = { tomster: true };

assert.equal(get(obj, ''), undefined);
}

['@test should not access a property more than once'](assert) {
let count = 0;
let obj = {
Expand Down Expand Up @@ -177,7 +191,6 @@ moduleFor(
() => get(obj, false),
/The key provided to get must be a string or number, you passed false/
);
expectAssertion(() => get(obj, ''), /Cannot call `get` with an empty string/);
}

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

0 comments on commit 223dc58

Please sign in to comment.