ngMock
First include angular-mocks.js
in your HTML:
<script src="angular.js">
<script src="angular-mocks.js">
You can download this file from the following places:
//ajax.googleapis.com/ajax/libs/angularjs/X.Y.Z/angular-mocks.js
bower install angular-mocks@X.Y.Z
"//code.angularjs.org/X.Y.Z/angular-mocks.js"
where X.Y.Z is the AngularJS version you are running.
Then load the module in your application by adding it as a dependent module:
angular.module('app', ['ngMock']);
With that you're ready to get started!
The ngMock
module provides support to inject and mock Angular services into unit tests.
In addition, ngMock also extends various core ng services such that they can be
inspected and controlled in a synchronous manner within test code.
Name | Description |
---|---|
angular.mock | Namespace from 'angular-mocks.js' which contains testing related code. |
Name | Description |
---|---|
$exceptionHandlerProvider | Configures the mock implementation of |
Name | Description |
---|---|
$exceptionHandler | Mock implementation of |
$log | Mock implementation of |
$interval | Mock implementation of the $interval service. |
$animate | Mock implementation of the |
$httpBackend | Fake HTTP backend implementation suitable for unit testing applications that use the $http service. |
$timeout | This service is just a simple decorator for $timeout service that adds a "flush" and "verifyNoPendingTasks" methods. |
$controller | A decorator for |
$componentController | A service that can be used to create instances of component controllers.
Be aware that the controller will be instantiated and attached to the scope as specified in
the component definition object. That means that you must always provide a $scope object
in the locals param.
|
Name | Description |
---|---|
angular.mock.TzDate | NOTE: this is not an injectable instance, just a globally available mock class of |
$rootScope.Scope | Scope type decorated with helper methods useful for testing. These
methods are automatically available on any Scope instance when
|
Name | Description |
---|---|
angular.mock.dump | NOTE: this is not an injectable instance, just a globally available function. |
angular.mock.module | NOTE: This function is also published on window for easy access. |
angular.mock.inject | NOTE: This function is also published on window for easy access. |