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
1
vote
0 answers

Angular unit testing with ngMock - $timeout.flush() throws exception

I am using ngMock for unit testing and I need to use the $timeout.flush function in one of my tests, so I have added the two following lines to my test: $timeout.flush(); $timeout.verifyNoPendingTasks(); as indicated on…
1
vote
1 answer

Testing ngResource with httpbackend - Possibly unhandled rejection error

Problem I am attempting to test a the following controller using Karma, Mocha, Chai, PhantomJS IndexCtrl.js (simplified) app.controller('IndexCtrl', ['$scope', '$resource', function($scope, $resource) { var methods = { get:{ …
1
vote
1 answer

How to access component controller when testing?

I am trying to put together some tests of a component. I have the following describe(`selecting an item`, () => { let element, $scope; beforeEach(module('my-app')) beforeEach(inject(($compile, $rootScope) => { $scope =…
George Mauer
  • 117,483
  • 131
  • 382
  • 612
1
vote
3 answers

Flush $timeout in protractor

I'm writing test using protractor and it always waits when $timeout will finished. If I use ignoreSynchronization = true; it stops to wait and test runs ahead. But for my test I should set back ignoreSynchronization = false;. And when I set it to…
Gleb
  • 1,312
  • 3
  • 18
  • 36
1
vote
1 answer

AngularJS unexpected request ngmock

I get an unexpected request error on GET /#/car/view/0 where 0 is the :carId. It's for a basic angular crud application on a ngMock backend. The $httpBackend.whenGET(carUrl) works and gives back a list of all cars. The addCar() also works. I can't…
1
vote
0 answers

Decorated $log fails in unit tests because of ngMock

In out project we have decorated $log service, that exposes a method .prefix(). We use it like $log.prefix('Some Prefix text here'). This works fine in every module we use $log in, but not the unit tests: $log.prefix is not a function It has to do…
1
vote
0 answers

AngularJS Jasmine Unit Testing : Error: [$injector:unpr] Unknown provider: pServiceProvider <- pService

I am doing testing on a simple angular code but I am getting the following error. Error: [$injector:unpr] Unknown provider: pServiceProvider <- pService Here are the details: ProdModule.JS var sapp = angular.module('productsApp',…
1
vote
1 answer

Inject in ngMock for jasmine test not work

I have a problem with injection dependency service in my test. I tried inject in different ways, but problem still stays. Injection works only in one way, via var $injector = angular.injector(['app']); $auth = $injector.get('$auth'); but i…
1
vote
0 answers

Error: [$injector:unpr] Unknown provider: initData

I am writing unit tests for angularjs application. I am using karma,jasmine as the tools for writing and testing the unit test cases. Below are code components: app.js (function() { "use strict"; angular.module("indirectTax.core",…
santosh kumar patro
  • 7,231
  • 22
  • 71
  • 143
1
vote
0 answers

Angular promises fail to resolve in all subsequent unit tests (ngMock)

We've recently upgraded to Angular 1.5-rc0. One recent change to ngMocks destroys the $rootScope after every test. However, I'm struggling to figure out why promises we use inside our app never fire after the first time. Here's a test which…
helion3
  • 34,737
  • 15
  • 57
  • 100
1
vote
1 answer

ngMock complains unexpected request when request is expected

My ng app is working fine, but I am trying to write a ngMock test for my controller; I am basically following along the example on angular's website: https://docs.angularjs.org/api/ngMock/service/$httpBackend The problem I am running into is that it…
Ji He
  • 13
  • 4
1
vote
0 answers

$timeout.flush during protractor test

My website has an app-wide session timeout that is set as soon as the page loads. When testing in protractor, I would like to call ngMocks's $timeout.flush() to kill the timeout, but I have not figured out how to get a handle on the $timeout service…
gregmagdits
  • 251
  • 2
  • 4
1
vote
0 answers

Passing a function as argument to addMockModule

I have this weird issue where i'm passing a function to the addMockModule argument and it is being returned as a string in the form of: functionName: "functionlogic" Static references such as variables work fine. This is the code: var x = function…
magicode118
  • 1,444
  • 2
  • 17
  • 26
1
vote
1 answer

$httpBackend does not mock $.ajax(...) calls

Trying to create a mock for $.ajax calls using $httpBackend. The below mocking snippet worked fine for worked fine with $http.get('/phones') $httpBackend.whenGET('/phones') But when tried to use the same for $.ajax({ url: '/phones', …
0
votes
1 answer

How to reference an AngularJS module defined in a single HTML file from spec files

I have an AngularJS module defined in a single HTML file. Unfortunately, I cannot refactor it into separate files. I need to add unit tests with angular-mocks and jasmine, and I need to run the unit tests with Node.JS (i.e. npm jasmine). I would…
user11081980
  • 3,059
  • 4
  • 30
  • 48