Unit testing AngularJS HTTP requests in the RAW Stack

In the previous blog post we created some basic unit tests for the AngularJS movies controller. As I mentioned there was one set of tests missing and that was around the controller doing HTTP requests to the WebAPI backend. In a unit test typically don’t want to do those test for real. First of all we don’t want to take a dependency on some external state and equally important we don’t want the overhead of those requests. Fortunately AngularJS makes it easy to fake those requests and test the controller bits in isolation.   The $httpBackend service One of the … Continue reading Unit testing AngularJS HTTP requests in the RAW Stack

Unit testing the AngularJS code in the RAW Stack

In the previous post we refactored the JavaScript code for our AngularJS controller a bit to make it more testable. However we didn’t actually start writing any tests yet so lets create a few tests.   The AngularJS controller under test Just as a quick reminder the AngularJS controller in our previous code was as follows 1: (function () { 2: ‘use strict'; 3: var module = angular.module("myApp", []); 4:  5: module.controller("moviesCtrl", function ($scope, $http) { 6: $http.get("/api/movies").then(function (e) { 7: $scope.movies = e.data; 8: }); 9: 10: $scope.newMovie = { Title: "" }; 11: $scope.addMovie = function () { … Continue reading Unit testing the AngularJS code in the RAW Stack