jeudi 17 décembre 2015

Ember Unit Testing Components with bubble up action

I'm attempting to write a unit test to ensure that properties are closed upon the closing of a modal. However, I seem to be having issues with the action handling. I keep getting the error message:
Error: <q12-reports@component:add-team-modal::ember294> had no action handler for: hideModal

Here is the modal.js component:

stopSearch: function(modal) {
  modal.send('hideModal');

  this.setProperties({
    searchTerm: ''
  });
},

actions: {
  modalCancelled: function(modal) {
    this.stopSearch(modal);
  },
  etc...
}

As you can see I'm bubbling up the hideModal action. This is the unit test I'm attempting to write:

test('closing modal clears properties correctly', function(assert) {
  assert.expect(2);
  let component = this.subject();   
  let firstSearchTerm;

  Ember.run(function() {
    component.set('searchTerm', 'test');
    firstSearchTerm = component.get('searchTerm');
    assert.ok(firstSearchTerm, 'test', 'set term properly');
    component.send('modalClosed', component);
  });

  assert.ok(firstSearchTerm, '', 'clears term properly');
})

Before people mention this, I have tried it below.

test('closing modal clears properties correctly', function(assert) {
  assert.expect(2);
  let component = this.subject();   

  let firstSearchTerm;
  let $component = this.append();

  let targetObject = {
    externalHideModal: function() {
      assert.ok(true, 'hide modal was called.');
      return true;
    }
  }

  component.set('hideModal', 'externalHideModal');
  component.set('targetObject', targetObject);

  Ember.run(function() {
    component.set('searchTerm', 'test');
    firstSearchTerm = component.get('searchTerm');
    component.send('modalCancelled', component);
  });

  assert.ok(firstSearchTerm, '', 'clears term properly');
})




Aucun commentaire:

Enregistrer un commentaire