mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-09 22:39:39 +08:00
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
This commit is contained in:
committed by
Igor Minar
parent
3345bf8bc7
commit
0f6aa10413
8
src/ngMock/angular-mocks.js
vendored
8
src/ngMock/angular-mocks.js
vendored
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user