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
0
votes
2 answers

Angular unit testing error: Error: [$injector:modulerr]

I'm using angular 1.2.2, and angular mock 1.3.5. It's pretty simple testing code to test my own customized service. angular.module('factories', []) .factory('chimp', ['$log', function($log) { return { ook: function() { …
Bomin
  • 1,619
  • 5
  • 24
  • 39
0
votes
0 answers

AngularJS Jasmine error 'Controller is not a function' when instantiated with arguments

I have been doing angularJS for a while now (without tests) but I want to do it properly! I have a controller defined like so (function () { 'use strict'; angular.module('app') .controller('CarehomeListCtrl', ['$scope', 'carehomesDataService',…
Obi
  • 3,091
  • 4
  • 34
  • 56
0
votes
2 answers

Angular-mocks $injector doesn't return service, no $get method

I am attempting to do my best at bdd with Karma and Mocha. I have created this shell of a service to try to get things going (generated from TypeScript) I have created the following test I put a break point on the line where the injector gets the…
pthalacker
  • 2,056
  • 3
  • 20
  • 37
0
votes
1 answer

Angular-mocks error instantiating $rootScope

I have a very simple Mocha test (a copy of code that I have seen dozens of times) When I run it, angular mocks appears to successfully load the injected resources and all their dependencies and successfully makes it to line 9. When I step into the…
pthalacker
  • 2,056
  • 3
  • 20
  • 37
0
votes
1 answer

How can I access my service from module setup in Angular Jasmine Test?

I have the following in a jasmine test for angular... beforeEach(module('app')); beforeEach(module('app.services')); beforeEach(module(function ($provide, Config) { reservationCallerJquery = { reserveBooking: function…
Exitos
  • 29,230
  • 38
  • 123
  • 178
0
votes
1 answer

karma/angularjs how to test run block with service

This post follow this I've posted an other thread with a easier example code to test 'use strict'; var app = angular.module('myApp', []); app.run(function ($rootScope, Menus) { var menus = [ { 'permission':…
Whisher
  • 31,320
  • 32
  • 120
  • 201
0
votes
1 answer

karma/angularjs how to test run block with an asynchronous service

How can I test like: init.js lama.system module angular.module('lama.system', []) .config(['$httpProvider', function($httpProvider) { // Crossdomain requests not allowed if you want do cors request see filter.php …
Whisher
  • 31,320
  • 32
  • 120
  • 201
0
votes
1 answer

karma/jasmine/angular toHaveBeenCalledWith is really called

in my app for instance I've got $rootScope.$emit('loggedin',data.user); $rootScope.$on('loggedin', function(event,user) { console.log('called'); }); in my test spyOn($rootScope, '$emit'); var response = { "success":1, …
Whisher
  • 31,320
  • 32
  • 120
  • 201
0
votes
2 answers

angular-mocks ignoring request

I am trying to use the $httpBackend service of Angular (v1.2.15) but it just ignores my request. As you see, I have planned two kind of requests, one for html documents and another one for REST requests. However, nothing happens when I do the…
Eduardo Páez Rubio
  • 1,032
  • 2
  • 9
  • 31
0
votes
1 answer

How to write behavioral/functional/endpoint tests using Angular and Jasmine + $resource?

I want to write functional test of the server's endpoints. I'm not doing e2e testing. This is more of a functional/behavioral test. beforeEach(inject(function ($injector) { f = $injector.get('WidgetFactory'); })); it('should…
FlavorScape
  • 13,301
  • 12
  • 75
  • 117
0
votes
1 answer

AngularJS $httpBackend expectGET not working

I am writing QUnit tests for an AngularJS factory. Here's the code for the factory: var app = angular.module('App', []); app.factory('$groupFactory', function($rootScope, $http) { return { 'getAll': function(_callback) { …
Raghava Kotekar
  • 471
  • 5
  • 8
0
votes
1 answer

AngularJS initialise backendless testing

I have AngularJS + RequireJS app. My task is to create a backendless version for UI development purposes. So a version where some/all HTTP requested are mocked. The desired user flow is: User goes to /debug to initialise a backendless version. User…
Tomasz Jureczko
  • 167
  • 3
  • 10
-1
votes
1 answer

Unit test controller

I make an ionic app and it finish but when i start to add tests to it I face a problem with $resources ,in this case I have this Controller : .controller('newAccountCtrl', function($scope, $window, $rootScope, API, $ionicPopup, $state) { …
-1
votes
1 answer

Why does expectPUT/POST/etc represent request bodies as a string?

Look at the API for $httpbackend, we can see that functions like expectPut can take up to 4 parameters. The second parameter can be a function which takes 1 parameter: a string. This string represents the body of the HTTP request. But why is it a…
1 2 3
13
14