随机失败的验收测试错误:断言失败:在被破坏的对象上调用set

时间:2015-11-24 12:08:25

标签: testing ember.js

我的一些验收测试(涉及操作)在与所有其他测试一起运行时会随机失败,但在我单独运行它们时永远不会失败。

Error: Assertion Failed: calling set on destroyed object在我的操作中被触发

使用该表作为用户时,我没有遇到任何问题,因此这些问题仅出现在测试中。所以我不确定是不是因为每次运行后应用程序都没有被正确销毁。

我能否以某种方式了解为什么对象即将被销毁或哪些观察者阻止它?

FOOS /索引/ route.js

startFoo(foos) {
  foos.forEach(function(foo) {
    foo.set('status', 'active');
    foo.save();
  });
},

action传递给显示foo - 模型列表的组件(表)。可以选择每一行,这样就可以将此行的foo模型添加到此表组件的属性selectedRows

组件/我的表/ table.js

visibleColumns: Ember.A(),
selectedRows: Ember.A(),

selectRow(row) {
  let selectedRows = this.get('selectedRows');
  if (selectedRows.contains(row)) {
    selectedRows.removeObject(row);
  } else {
    selectedRows.addObject(row);
  }
},
isSelected(row) {
  return this.get('selectedRows').contains(row);
},

组件/我的表/报头/ template.hbs

action.cb是函数startFoo

<button {{action action.cb table.selectedRows}}>
  {{im-icon icon=action.icon}}
</button>

表组件非常模块化,因此它具有headercolumnscellsrows并且共享状态(如所选行)我使用{{ 1}}传递给表组件的所有部分(这可能是问题?!!?)

组件/我的表/行/ component.js

Ember.Object

组件/我的表/行/ template.hbs

isSelected: computed('table.selectedRows.[]', { get(/*key*/) { return this.get('table').isSelected(this.get('content')); }, set(/*key, value*/) { this.get('table').selectRow(this.get('content')); return this.get('table').isSelected(this.get('content')); }, }), content型号

foo

测试

设置和拆解为<td class="shrink">{{input type='checkbox' checked=isSelected}}</td> {{#each table.visibleColumns as |column|}} {{my-table/cell content=content column=column}} {{/each}} default

ember-cli

1 个答案:

答案 0 :(得分:0)

在设置之前检查isDestroyed应该可以解决问题

isSelected: computed('table.selectedRows.[]', {
  get(/*key*/) {
    return this.get('table').isSelected(this.get('content'));
  },
  set(/*key, value*/) {
    if (this.get('isDestroyed')) {
      return;
    }
    this.get('table').selectRow(this.get('content'));
    return this.get('table').isSelected(this.get('content'));
  },
}),