Currently, my project is utilizing AngularJS along with Kendo-UI. I am facing an issue while attempting to test one of my Controllers that incorporates a Kendo-UI Grid:
angular.module('myApp')('DevicesCtrl', function ($scope) {
$scope.gridOptions = {
dataSource: {
transport: {
read: {
url: "/devices",
dataType: "json"
}
},
change: function(){
var view = this.view();
$scope.devices = [];
$.each(view, function(i, v) {
$scope.devices.push({id: v.id, description: v.name, status: v.status == 0 ? "failure" : "success"});
});
$scope.$apply();
}
},
columns: [
{
field: "name",
title: "Name",
width: 250,
template: function (item) {
var itemStatus = item.status == 0 ? 'failure' : 'success';
return '<div label size="small" operation="' + itemStatus + '" label="' + item.name + '"></div>';
}
},
{
field: "status",
title: "Status"
}
]
};
});
While creating my unit test, I had expected a GET request to be triggered:
describe('deviceCtrl', function () {
var scope, deviceCtrl, httpBackend, timeout;
beforeEach(module("myApp"));
beforeEach(module('src/modules/devices/views/device.html'));
beforeEach(inject(function ($controller, $rootScope, $httpBackend, $timeout, $state) {
scope = $rootScope.$new();
httpBackend = $httpBackend;
timeout = $timeout;
httpBackend.expectGET('languages/en_US.json').respond({});
deviceCtrl = $controller("DeviceCtrl", {
$scope: scope
});
$state.go("devices");
timeout.flush()
}));
it('should load the switch list', function () {
httpBackend.expectGET("/devices").respond(
[{"id":"1","name":"name 1","status":"1"},
{"id":"2","name":"name 2","status":"2"}]
);
httpBackend.flush();
});
});
However, I found that the anticipated expectation was not met as no requests were initiated. Hence, my query pertains to whether there exists a method to compel Kendo Grid/Datasource to make this call, allowing me to simulate it?
In my research, I stumbled upon some instances illustrating how Mockjax could achieve this (http://www.telerik.com/forums/best-practice-mocking-with-datasource). Nevertheless, I would prefer to explore utilizing angular libraries for this purpose.