Here is a snippet of what my service implementation looks like:
TestService.initializeDefaults = function() {
var qPromise = $q.defer();
$q.all({
localResource: localResource.fetch(),
item: itemResource.fetch()
}).then(function(directories) {
// perform operations with directories
$q.all({
thing1: anotherThingFetch.fetch(),
thing2: someThingFetch.fetch(),
thing3: thingFetch.fetch()
}).then(function(funData) {
// perform operations with the data
preventiveServicesService.fetch().then(function() {
// more operations
});
});
}.bind(this));
return qPromise;
};
I am working on using Karma to test whether all the functions within the initializeDefaults method have been executed successfully. This means ensuring that all fetch requests have completed. Here's a snippet of my current test code:
it("should initialize defaults (Scenario 1)", function() {
service.initializeDefaults();
rootScope.$apply();
expect(localResourceMock.fetch).toHaveBeenCalledWith();
expect(itemResourceMock.fetch).toHaveBeenCalledWith();