I have a requires controller file which defines Backbone Models and Views into its structure and then with every different functionality of the model it invokes its corresponding Rest Web Service call. Following is the structure of my controller :-
define([ 'core/libs', 'modules/test/mapping/models/TestModel' ], function(libs, TestModel) {
var testModel = TestModel.testModel;
testModel.on("executeSimulatorButton", function() {
$("#simulatorMessage").html("Executing simulator ...");
testModel.get("executeSimulator").set("endDate", $("#datepickerReportingEnd").datepicker().val());
testModel.get("executeSimulator").set("startDate",$("#datepickerReportingStart").datepicker().val());
testModel.get("executeSimulator").invokeGet();
});
testModel.get("executeSimulator").on("update", function() {
$("#simulatorMessage").html(testModel.get("executeSimulator").get("value"));
});
testModel.on("truncateSimulatorButton", function() {
$("#simulatorMessage").html("Truncating simulator results...");
testModel.get("truncateSimulator").invokePost();
});
testModel.get("truncateSimulator").on("update", function() {
$("#simulatorMessage").html(testModel.get("truncateSimulator").get("value"));
});});
And in my jasmine spec file I am including the controller like this -
define(
[ 'modules/test/mapping/controllers/TestController','modules/test/mapping/models/TestModel'],
function(controller,TestModel) {
describe("TestController :", function() {
it("should create an test instance", function() {
console.log("testcontroller: " + controller);
expect(controller).not.toBe(null);
});
});
describe("TestController :", function() {
it("should test testModel instance", function() {
var testModel=TestModel.testModel;
expect(testModel.on("executeSimulatorButton",jasmine.any(Function))).toBeDefined();
});
});
});
The above code is not throwing any error but the part of executeSimulatorButton is not getting covered in the controller. I cannot directly use the controller variable in my jasmine test because the console.log is printing undefined in place of [Object object]. I found many solutions with respect to AngularJS but since I am not using Angular, I don't know how to test the controller. What is the way to test and get code coverage for this type of controllers using jasmine?