Skip to Content
0

QUnit tests for functions using events

Feb 13, 2017 at 05:13 PM

39

avatar image

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)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Veeraraghavan Narasimhan
Feb 14, 2017 at 12:47 AM
0

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

Show 1 Share
10 |10000 characters needed characters left characters exceeded
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.
0