Questions tagged [angularjs-ngmock]

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.

57 questions
0
votes
1 answer

AngularJS - How to mock a controller for a template?

I have a template with behavior I want to test, but it invokes a controller with code I'd like to avoid, and I'd rather inject a mock for it. How do I do that? I am using Angular 1.7, Karma, and Jasmine. Template:
wizulus
  • 5,653
  • 2
  • 23
  • 40
0
votes
1 answer

How do you use unit test a factory using $provide and $q

I'm trying to write a unit test for a service that has a dependency on another factory function that returns a promise. I've followed the process as seen in this question and answer, but for some reason the code in the then() that I'm trying to…
BlackICE
  • 8,816
  • 3
  • 53
  • 91
0
votes
1 answer

Unexpected request error when unit-testing angular $http service

I'm using unit-testing in my angularJS application. Here's a test spec I have for a service: describe('service', function () { var service = {}; var $httpBackend; beforeEach(module('myApp')); beforeEach(inject(function (_service_,…
ataravati
  • 8,891
  • 9
  • 57
  • 89
0
votes
1 answer

Jasmine test with angular ng-mock not working with controller and promise

I have been playing a bit with the following code and I am not able to find the issue, the test fails wit the following message: "Expected undefined not to be undefined." I have a Service which returns a promise to my controller. In the controller,…
MarcosF8
  • 1,848
  • 5
  • 19
  • 33
0
votes
0 answers

$httpBackend is not injected

I have the following problem (with mock tests): I get it after angular migration to v 1.6. It looks like $httpBackend is not injected. I don't have any ideas why this provider is not injected. My injection block: Thank you for any ideas.
0
votes
1 answer

Cannot get correct result from mock $httpBackend service

I have a function: function validateClub(club) { //.. other validation let existingClub $http.get('/clubs/fetch/' + club.clubName).then(data => { existingClub = data }, err => { $log.error(err) }) console.log(existingClub) …
Rodders
  • 2,425
  • 2
  • 20
  • 34
0
votes
1 answer

Unit Testing Services in AngularJS with Jasmine, Karma and ng-Mock

I'm having trouble accessing my services and filters in unit tests (I haven't tried directives yet). I've written unit tests before, but as I have moved to the configuration of our builds, I'm having trouble accessing our new services to write unit…
0
votes
2 answers

Frozen promise in a unit test

I have hit a strange thing when trying to test a service returning ordinary $q promise. No promise I try in any test is actually being ever resolved/rejected (more specifically handlers from then are not called, code inside promise runs just fine).…
monnef
  • 3,903
  • 5
  • 30
  • 50
0
votes
1 answer

How to configure Angular Provider in unit test?

I'm trying to create tests for a provider, but I can't seem to configure it in the test. Here's my provider with which I'm configuring a service with a url when it gets instantiated: angular.module('PRXHttpData', []) .provider('HttpData',…
Dallin
  • 1,075
  • 13
  • 28
0
votes
1 answer

ngMock not injecting factory

I have been stuck on this problem for the past 24 hrs and cannot see what is wrong with my code here. I am getting an injector error from Angular and cannot understand why. Here is my code: (function (){ 'use strict'; angular.module('Test',…
0
votes
0 answers

Angular testing controller using mock factory which returns promise

I'm trying to test an Angular controller and mock a factory so that I can use it within this same test. I'm fairly new to Angular testing & have been having trouble figuring out how to this. My factory, doesn't use the $http rather the $q service,…
0
votes
1 answer

Angular App works great but ngMock NOT loading Modules properly

My app works fine when i deploy it and run it in a browser I can successfully reach all my controllers/services. and they were linked together via submodules. I used submodules to organize the states/routes better for ui-router. (Previously we had…
Stevers
  • 516
  • 5
  • 11
0
votes
1 answer

Angular ngMocks error in $log

I'm having issues with ngMocks and the $log provider that is mocked in there. Anytime a use $log in my code, the tests fails, because of the mock for $log fail at (line 295): var $log = { log: function() { $log.log.logs.push(concat([], arguments,…
teone
  • 2,153
  • 3
  • 25
  • 49
0
votes
1 answer

Why angular module's factory method should be redefined in the test mock

in an angular.js tutorial , i found this example of a factory testing : the module : angular.module('omdbModule', []) .factory('omdbApi', function omdbApiFactory() { return { search: function() { …
Bardelman
  • 2,176
  • 7
  • 43
  • 70
0
votes
0 answers

AngularJS: Mock specific $http calls

I'm working on an AngularJS application that makes numerous $http calls. Most of these are working fine: the backends exist and returns the appropriate data. What I'm working on right now makes calls against an incomplete backend. How can I mock…
ricksmt
  • 888
  • 2
  • 13
  • 34