灰烬单元测试的计算属性然后

用户名

我有以下模型: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;
    }
  }),

我尝试对其进行单元测试: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);
});

但是console.log始终显示为null。是否可以等到计算出的属性运行之后再设置新值?

约翰·罗伊斯(John Roys)的篮子

你说let value = null;,但是永远不要将值设置为其他任何值,而只是返回值。是的,它将始终记录为null。可能您想设置value = this.get('invoices'),然后返回它。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章