From 36374e67d32569eb4b1eabdaff532dc83ec40075 Mon Sep 17 00:00:00 2001 From: "Lucas N. Munhoz" Date: Fri, 10 Oct 2014 16:38:50 -0300 Subject: [PATCH 1/2] docs($httpBackend): add module declaration for best understanding According with the Issue #9537. This module declaration in the test is very important. When I started to test in angular I copy and paste this code to see how it works, and I get this `module undefined error`, and just after read some blog posts I figure out that this line is essential for testing your module. So, for best understanding of begginers this can be very helpful. --- src/ngMock/angular-mocks.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ngMock/angular-mocks.js b/src/ngMock/angular-mocks.js index 9690b46391c0..a216570e1f6d 100644 --- a/src/ngMock/angular-mocks.js +++ b/src/ngMock/angular-mocks.js @@ -994,6 +994,11 @@ angular.mock.dump = function(object) { * First we create the controller under test: * ```js + // The module code + angular + .module('MyApp') + .controller('MyController', MyController); + // The controller code function MyController($scope, $http) { var authToken; @@ -1022,6 +1027,9 @@ angular.mock.dump = function(object) { // testing controller describe('MyController', function() { var $httpBackend, $rootScope, createController, authRequestHandler; + + // Set up the module + beforeEach(module('MyApp')); beforeEach(inject(function($injector) { // Set up the mock http service responses From 1a53a185163eb4f404e1c6897924368568297aab Mon Sep 17 00:00:00 2001 From: "Lucas N. Munhoz" Date: Fri, 10 Oct 2014 17:30:49 -0300 Subject: [PATCH 2/2] Fix declaration of module. Was getting instead of settings a new one. --- src/ngMock/angular-mocks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ngMock/angular-mocks.js b/src/ngMock/angular-mocks.js index a216570e1f6d..b9de90ae0bb0 100644 --- a/src/ngMock/angular-mocks.js +++ b/src/ngMock/angular-mocks.js @@ -996,7 +996,7 @@ angular.mock.dump = function(object) { ```js // The module code angular - .module('MyApp') + .module('MyApp', []) .controller('MyController', MyController); // The controller code