From 0f6aa104136eda84eebc682c3875fc0a9bb3fde0 Mon Sep 17 00:00:00 2001 From: "Lucas N. Munhoz" Date: Fri, 10 Oct 2014 16:38:50 -0300 Subject: [PATCH] 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. Closes #9563 --- 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 9690b463..2ef2f32d 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; @@ -1023,6 +1028,9 @@ angular.mock.dump = function(object) { 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 $httpBackend = $injector.get('$httpBackend');