mardi 24 novembre 2015

randomly failing acceptance-tests with Error: Assertion Failed: calling set on destroyed object

Some of my acceptance-tests (which involve actions) fail randomly when run with all other tests but never fail when I run them in isolation.

The Error: Assertion Failed: calling set on destroyed object is triggered in my action

I don't get any issue while using the table as a user so these issues only appear in tests. So I'm not sure if it's just because the app isn't destroyed correctly after each run.

Can I somehow see why the object is about to be destroyed or which observers are blocking it?

foos/index/route.js

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

This action gets passed down to a component (table) which shows a list of foo-models. Each row can be selected, doing so add the foo model of this row to a property selectedRows on this table component.

components/my-table/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);
},

components/my-table/header/template.hbs

action.cb is the function startFoo

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

The table component is pretty modular so it has header, columns, cells, rows and to share the state (like selected rows) I use an Ember.Object which is passed to all parts of the table component (which might be the issue?!!?)

components/my-table/row/component.js

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'));
  },
}),

components/my-table/row/template.hbs

content is a foo model

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

Test

setup and teardown is ember-cli default

moduleForAcceptance('Acceptance | Foos');

test('click on action start changes state to active', function(assert) {
  server.create('foo', {
    status: 'paused'
  });

  // This is an ember-page-object
  fooPage
    .visit()
    .selectFoo()
    .clickStart();

  andThen(function() {
    assert.equal(fooPage.foos(1).status(), 'active', 'runs action');
  });
});

Aucun commentaire:

Enregistrer un commentaire