I have a controller using a service (using $resource) and I am trying to mock the response of the service method. Although I have successfully mocked the service method including a response for that method, the callback in the controller (which is the piece of code I am trying to test, is never being called).
This is my mock.
var props = [
{ Uid: "123", Name: "Prop 1" },
{ Uid: "456", Name: "Prop 2" },
{ Uid: "789", Name: "Prop 3" }
];
var mockPropertyService;
beforeEach(inject(function ($q) {
mockPropertyService = {
query: function () {
return $q.when(props);
}
};
}));
Then i inject my mock service into my controller, which is definitely working.
var controller = $controller("PropertiesCtrl", { $scope: scope, Property: mockPropertyService});
$rootScope.$apply();
expect(.......)
The query method is available on the mock service and is being successfully called in the controller in the code below. But the response call back function is not being called.
Here is the controller code I am trying to test
$scope.loadProperties = function () {
return Property.query({ embed: 'models' }, function (properties) {
//I am trying to test this code in here
//But the test execution never gets to here
//but it also doesnt throw an exception
console.log(properties);
_.each(properties, function (p) {
p.PictureUrl = p.getThumbnailUrl();
p.Calculated = p.isCalculated();
p = Property.loadWorkflows(p);
});
});
};
What am I doing wrong that the callback function is never being called?
Can anyone help or advise me on this - i have tried everything I can think of.