I have SAPUI5 app that I'm trying to unit test using QUnit.
The code I'm trying to test is the following.
myFunction: function(flag, obj){
var myModel = new sap.ui.model.json.JSONModel();
if(flag){
pricingModel.loadData("filePath", null, false);
}
....
obj.getView().setModel(myModel, "myModel");
}
this function is located on a different file than my controller and is called from my controller like this.
...
previous logic sets flag = true;
...
dataConnector.myFunction(flag, this); //where 'this' is the reference to he Main this of the application
Here is my unit test snippet
QUnit.test("Valid NSN Input", function(assert) {
// Arrange
var validInputEvent = {
getParameters: sinon.stub().returns({ value: '306018040' })
};
var getValue = sinon.stub().returns('306018040');
var setValue = sinon.spy();
var apply = sinon.stub();
var controls = {
dataConnectionFlag: true,
nsnSearchInput : {
getValue: getValue,
setValue: setValue
},
};
//Checking onFilterNSN when input has a valid value
mainController.onSearch(validInputEvent, controls);
So to clarify everything above, I'm calling a function located on file.js from controller.js and passing in the 'this' reference so I can set my data model with that other file. Everything works fine when I run the application but the unit test fails as it doesn't know what the 'this' reference is. Is there a way to make this test work?
Aucun commentaire:
Enregistrer un commentaire