Reputation: 1056
I have the following model: partner.js
invoices: hasMany('invoice'),
resolvedInvoices: computed('invoices', {
get(){
let value = null;
let _this = this;
this.get('invoices').then(invoices=>{
_this.set('resolvedInvoices', invoices);
});
return value;
},
set(key,value) {
return value;
}
}),
I try to unit test it: partner-test.js
test('test', function(assert) {
let partner = this.subject();
let store = this.store();
// set a relationship
run(() => {
let invoice = store.createRecord('invoice', {
});
partner.get('invoices').pushObject(invoice);
console.log(partner.get('resolvedInvoices'));
});
assert.ok(true);
});
But console.log always shows null. Is it possible to wait till the computed property's then runs, and the new value sets?
Upvotes: 0
Views: 206
Reputation: 2661
you say let value = null;
, but then never set value to anything else, and just return value. So yeah, it would always log null. Probably you want to set value = this.get('invoices')
, and then return that.
Upvotes: 1