In my AngularJS Controller, I have a $scope.init method that gets called when the controller gets initialized. $scope.init calls $scope.loadData and $scope.loadNames, which each fire an HTTP GET Request to an API to fetch some data.
I have written some unit tests using $httpBackend to mock the API responses and test $scope.loadData and $scope.loadNames. Those work fine but something that I can't seem to test is the $scope.init method. Is there a way to mock or stub a method that gets called on controller initialization? What are the best practices for this?
Aucun commentaire:
Enregistrer un commentaire