How to unit test Angular’s $resource and $http

Unit testing of Angular’s underlying $http can be very tricky. I’ve some spent considerable time to get the unit testing up and running. What was running OK in a live application, was not working at all in a unit test. I was getting error message “No pending request to flush !” all the time. My controller looked something like this //TypeScript Module.controller(“UsersCtrl”, [<any> “$scope”, “$location”, “User”, function ( $scope, $location : ng.ILocationService, User: ng.resource.IResourceClass) { $scope.findUsers = () => { User.query({ email: $scope.searchTerm, showAdHoc: $scope.showAdHoc }, function (data: any) { //data arrived. Do something with them }, function (errorData: any) …

Continue Reading