Questions tagged [angular-mock]

angular-mock (or ngMock) is a module of the AngularJS framework providing features helpful for testing.

The angular-mock provides features helpful to the testing of AngularJS applications. Features include:

  • mock implementations for exception handling, logging, the http backend, and timeouts
  • facilities to help inject objects needed for tests
  • facilities to help inject mock objects which are used by the system-under-test.

To use it add angular.js and angular-mock.js to the HTML file.

209 questions
3
votes
1 answer

Unit Testing $routeParams in directive

I have a directive that accesses the $routeParams of the page as such: myApp.directive("myList", function ($routeParams) { return { restrict: 'E', templateUrl: 'tabs/my-list.html', link: function (scope) { …
3
votes
2 answers

Using Jasmine to spy on document.createElement throws error from angular mock

I have an Angular service that handles the webcam. Here is the function I'm trying to test: this.takePicture = function() { var canvas = document.createElement('canvas'); canvas.width = this.width; canvas.height = this.height; var…
3
votes
2 answers

cannot use beforeEach with the inject function

This is from the karma.conf.js file: module.exports = function (config) { config.set({ frameworks: ['mocha', 'chai'], files: [ 'bower_components/angular/angular.js', 'bower_components/angular-mocks/angular-mocks.js', …
commonUser
  • 599
  • 1
  • 6
  • 17
3
votes
1 answer

Angular/Karma: Error: [$injector:nomod] Module 'module' is not available

So I'm trying to use the Karma test runner on my Angular project, but I keep getting this error: Error: [$injector:nomod] Module 'app.auth' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure…
realph
  • 4,481
  • 13
  • 49
  • 104
3
votes
2 answers

External promises never finish in unit tests with ngMock

I'm trying to unit test the resolution/rejection of external promises. The problem is that those promises are never finished when ngMock module is injected - which is mandatory, as I'm triggering HTTP requests and timeouts. Take for example…
gustavohenke
  • 40,997
  • 14
  • 121
  • 129
3
votes
1 answer

AngularJS : $httpBackend mock only some requests

I use ngMock module to mock a several requests like so: $httpBackend.whenGET("/accounts").respond([obj]); However, it seems that loading the module expects you to mock ALL requests. So if I do any other request other than those I mocked, I get…
parliament
  • 21,544
  • 38
  • 148
  • 238
3
votes
2 answers

Angular Mocks install ask me for dependencies

Sincerely I don't know what to answer ... I'm newbie in Ionic + Angular ... I'm trying to install Angular Mocks but it says about Angular version. $ sudo bower install angular-mocks --allow-root bower angular-mocks#* cached…
FlamingMoe
  • 2,709
  • 5
  • 39
  • 64
3
votes
1 answer

Jasmine - Testing if Controller Exists Getting Error

i have a simple controller: app.controller("RegisterController", function ($scope, $location) { // Do something }); And all i am trying to do is to test this controller is defined: describe('RegisterController', function() { var…
Oam Psy
  • 8,555
  • 32
  • 93
  • 157
3
votes
2 answers

How to mock socket.io with Angular and Jasmine

I'm having trouble figuring out how to correctly mock Socket.io in an Angular application using Jasmine and Karma. Here are the files found in…
Paymahn Moghadasian
  • 9,301
  • 13
  • 56
  • 94
3
votes
1 answer

Controller not working when ngMock is included

My code without ngMock is 'here'. var app = angular.module('logExample',[]); app.controller('LogController', ['$scope', '$log', function($scope, $log) { $scope.$log = $log; $scope.message = 'Hello World!'; }]); When I add 'ngMock' in the angular…
Tehreem
  • 476
  • 9
  • 23
3
votes
1 answer

AngularJS - interval doesn't get flushed

I have the angular service function that I am willing to test: doSomeTask: function (ids, callback) { $http.put('/get_job', {'ids': ids}).success(function (data) { var statusCheck = $interval(function() { $http.get('check_status?=' +…
alexs333
  • 12,143
  • 11
  • 51
  • 89
3
votes
1 answer

Angular.mock.$interval.flush() throws strange exception

I have created the following small controller for testing that the interval function is triggered at the specified interval angular.module('app').controller('myTstController', [ '$interval', function($interval) { var called = 0; …
Eebo
  • 49
  • 1
  • 9
3
votes
1 answer

access POST data from httpBackend in e2e test

In this example, I have an e2e test doing a button click, which executes a function that does a POST I would like to be able to have access to the "data" object from testDev httpBackend callback, in my e2e scenerios code, for verification. Is this…
koolunix
  • 1,995
  • 16
  • 25
2
votes
1 answer

Unit test $mdDialog angular material

I called one $mdDialog inside a function. I want to unit-test $mdDialog ok and cancel cases. The below is my controller code (app.controller.js). (function () { 'use strict'; app.controller('AppCtrl', AppCtrl); AppCtrl.$inject =…
2
votes
1 answer

Why am I getting this Angular-Mock error and Mocha test is not running

I'm getting the exact error as found here: (window.beforeEach || window.setup) is not a function. However the fix did not work, the author of the tutorial series here even mentioned the same fix. Here is the Tuts+ author's fix: Which is simply to…
Leon Gaban
  • 36,509
  • 115
  • 332
  • 529
1 2
3
13 14