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.
Questions tagged [angularjs-ngmock]
57 questions
9
votes
1 answer
$httpBackend .whenGet is not a function in Angular
I am trying to make a dummy service to get data in Angular, I am using ngMockE2E, and my code for the Mock looks like this:
(function () {
"use strict"
var app = angular
.module("productResourceMock", ["ngMockE2E"]);
…

David Hemsey
- 277
- 3
- 11
7
votes
3 answers
$httpBackend.flush() method throws Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting
I am trying to unit test my AngularJS application using Karma and Jasmine. I want to mock the $http service. For that, I am using the $httpBackend method. Below is my service that I want to test:
angular.module('MyModule').factory('MyService',…

Jagrut
- 922
- 7
- 21
3
votes
0 answers
Ng-mock: $compileProvider doesn't have method 'preAssignBindingsEnabled`
I've been rewriting directives in Angular 1.5.8 to components. I want to write unit tests with '$componentController` just like described here: https://docs.angularjs.org/guide/component.
The problem is that I'm getting error at this line:
var ctrl…

pennyroyal
- 230
- 3
- 12
3
votes
1 answer
AngularJS module NgMockE2E's passThrough() method doesn't work
I have a sails, node-js application in angular-js and I decided to make some tests for it, especifycally in the backend part, for which I am using Jasmine and ngMockE2E tools, because I want to test it with some real server side data.
Here is a part…

Sergio Pascual
- 31
- 4
3
votes
1 answer
Angular 1.5 component unit testing with webpack
I'm trying to test a component with controller, with some bindings:
class AppSpecificController {
constructor() {
this.text = this.initialText ? this.initialText : 'No initial text has been specified.';
}
}
export const AppSpecificComponent…

Chris Jager
- 123
- 9
3
votes
0 answers
AngularJS $httpBackend asynchronous response
I'm trying to mock the back-end for an AngularJS(1.3.8)-app with ngMockE2E as replacement until the back-end code has been written.
I'm using already existing services that also query other data, however they return a promise. I am aware that…

C. Hacker
- 53
- 5
3
votes
0 answers
Angular JS with ngMock & Jasmine causing Promise issue
I am new to Jasmine JS & ngMock.
When I am trying to inject ngMock in angular & accessing $location service for injecting in controller for Testing purpose.
I am not getting promise response. Please help me.
I am getting below error
Error: Timeout…

HaRdik Kaji
- 390
- 1
- 11
3
votes
1 answer
Loading ngMock only in testing context when using Protractor
I'm switching all of our protractor E2E tests of an angular app to ngMock, so that we can mock our resources/http calls. However, I can't find a recommended method for loading ngMock in that scenario.
I don't want to include the script itself in my…

helion3
- 34,737
- 15
- 57
- 100
3
votes
1 answer
Unexpected Request Error with $HttpBackend (AngularJS)
I am using HttpBackend to mock some Http responses for some calls that my Angular app is making.
However, I am getting the error "Unexpected Request: [object Object] undefined" when I run my tests.
I know that usually this error means you're missing…

Angel Gao
- 478
- 1
- 5
- 12
3
votes
2 answers
angular ngMock $httpBackend: split mocks into multiple files
I am working on a big angular application which needs to mock entire API in the browser (also called backend-less development). I will have lots of different sections and views in my application, each of them will have its own mock definitions.
I do…

ducin
- 25,621
- 41
- 157
- 256
2
votes
1 answer
Angularjs ngMock inject before each test or on each test case?
Scenario
I'm currently writing tests for an Angular project, and almost on every article I find, I see them creating "global" variables in a describe block, where they store dependencies to be used in the tests, like this:
describe('Some tests',…

CupOfJoe
- 519
- 1
- 5
- 14
2
votes
1 answer
How to mock one-way binding parameters with $controller decorator?
I am writing tests for a directive's controller whose startup logic requires some one-way bound parameters to be defined. I am facing difficulties passing one-way bound parameters to the mocked controller. text-bound parameters are passed without…

Tristan Hamel
- 131
- 1
- 2
- 6
2
votes
1 answer
ngMock injecting $scope local into controller
This is a continuation of another question I asked that was successfully answered.
I'm learning how to unit test AngularJS applications with Karma, Jasmine, and ngMock. Here's the code I have a question about:
describe('myController function',…

bobbyz
- 4,946
- 3
- 31
- 42
2
votes
2 answers
Dynamically load JSON for ngMock httpBackend response in Protractor
I'm building an ngMock httpBackend in a Protractor test.
var mockJson = require(projectRoot + 'mock/load.json');
var mockResource = function() {
angular.module('aMockObject', ['myApp', 'ngMockE2E'])
.run(function($httpBackend) {
…

helion3
- 34,737
- 15
- 57
- 100
2
votes
2 answers
Where to declare ngMock module
I've just started wading through unit and end-to-end testing for an angular app.
I'm confused as to where I should declare the ngMock and ngMocke2e modules. My bower.json file has the reference to ngMock, and the index.html file is pointing to…

abyrne85
- 1,370
- 16
- 33