jeudi 30 juin 2016

Ember unit test computed property with then

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?

Aucun commentaire:

Enregistrer un commentaire