Skip to content

Commit

Permalink
[BUGFIX lts] Ensures that computed can depend on dynamic hash keys
Browse files Browse the repository at this point in the history
Ensures that computeds can depend on dynamic hash keys that did not
exist on the original hash.
  • Loading branch information
Chris Garrett committed May 27, 2021
1 parent ac8fd26 commit 167be20
Showing 1 changed file with 54 additions and 0 deletions.
Expand Up @@ -219,6 +219,60 @@ moduleFor(
this.assertText('Godfrey Chan');
}

['@test works with computeds on non-defined properties']() {
let instance;

let FooBarComponent = Component.extend({
init() {
this._super(...arguments);

if (HAS_NATIVE_PROXY) {
expectDeprecation(() => {
set(this.hash, 'lastName', 'Hietala');
}, /You set the '.*' property on a {{hash}} object/);
} else {
set(this.hash, 'lastName', 'Hietala');
}

instance = this;
},

fullName: computed('hash.firstName', 'hash.lastName', function () {
return `${this.hash.firstName} ${this.hash.lastName}`;
}),
});

this.registerComponent('foo-bar', {
ComponentClass: FooBarComponent,
template: `{{this.fullName}}`,
});

this.render(`{{foo-bar hash=(hash firstName=this.firstName)}}`, {
firstName: 'Chad',
lastName: 'Hietala',
});

this.assertText('Chad Hietala');

runTask(() => this.rerender());

this.assertText('Chad Hietala');

runTask(() => {
set(this.context, 'firstName', 'Godfrey');

if (HAS_NATIVE_PROXY) {
expectDeprecation(() => {
set(instance.hash, 'lastName', 'Chan');
}, /You set the '.*' property on a {{hash}} object/);
} else {
set(instance.hash, 'lastName', 'Chan');
}
});

this.assertText('Godfrey Chan');
}

['@test works when properties are set dynamically']() {
let fooBarInstance;
let FooBarComponent = Component.extend({
Expand Down

0 comments on commit 167be20

Please sign in to comment.