Skip to Content
avatar image
Former Member

QUnit tests for functions using events

Hi experts,

am unable to capture events in functions of Qunit tests

//function in controlleronSelectionChange: function(evt) {
var me = this;
var listItem = evt.getSource().getSelectedItem();
me._showDetail(listItem);
},

//in QUnit

QUnit.module("Table busy indicator delay",{
beforeEach : function () { this.oMasterController = new MasterController();
this.oTableStub = new ManagedObject();
this.oTableStub.getBusyIndicatorDelay = sinon.stub();
this.oViewStub = new ManagedObject(); this.oComponentStub = new ManagedObject(); 

//this.oComponentStub.setModel(new FakeI18n(), "i18n");

 sinon.stub(this.oMasterController, "getOwnerComponent").returns(this.oComponentStub);
sinon.stub(this.oMasterController, "getView").returns(this.oViewStub);
sinon.stub(this.oMasterController, "byId").returns(this.oTableStub);
}, 

afterEach : function () { this.oMasterController.destroy();
this.oTableStub.destroy(); this.oViewStub.destroy();
this.oComponentStub.destroy();
}
}); QUnit.test("onselction", function (assert) { // Act
//this.oMasterController.onInit();
//this.oMasterController.onInit();
this.oMasterController.onSelectionChange();      
// Assert assert.strictEqual(this.oMasterController.getOwnerComponent().getRouter(), "The original busy delay was restored");
});
capturee.png (37.8 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Feb 14, 2017 at 12:47 AM

    Hello ,

    Without getting too deep. One thing from the code i can see is that there is technically no event at all. What you are doing here is calling a JS function and not UI5 event.

    The way to trigger the event would be to get the instance of table and fire the table.fireSelectionChange() event and this mimicks the event. I have tried the following in OPA but not sure if Qunit is the preferred approach to test UI driven testing.

    Thanks and Regards,

    Veera

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member
      Hi Veeraraghavan Narasimhan,
      
      thanks for the reply
      
      onSelectionChange:function(evt){
      var me = this;
      var listItem = evt.getSource().getSelectedItem();
      me._showDetail(listItem);
      
      },
      this is my function and evt is my event.