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
3 answers

Angular return promise from httpBackend.when()

How do you return a promise from httpBackend.when()? I wanted to load some canned data stored in a .json file and return that from httpBackend.whenGET(). When I try to return the promise from http.get('mydata.json') the response is returned to the…
neridaj
  • 2,143
  • 9
  • 31
  • 62
0
votes
1 answer

angular-translate with angular-mocks results in blank page

I'm trying to mock a request/response using ngMock and get this error: Unexpected request: GET /locales/en_us.json. After digging around I found this post on how to get around the error. Adding $translateProvider.preferredLanguage('en_us') fixed the…
neridaj
  • 2,143
  • 9
  • 31
  • 62
0
votes
0 answers

Jasmine unit testing with $q.all in angular js factory service

Below is the service which get the values from web api using $resource (function () { 'use strict'; function a($resource) { return $resource('api/values/a'); } angular .module('app') .factory('a', ['$resource', a]);}()); i have a list…
0
votes
0 answers

Mocking multiple return values for a function that returns a success/error style promise?

NB: Code reproduced from memory. I have a method generated by djangoAngular that has this signature in my service: angular.module('myModule') .service('PythonDataService',['djangoRMI',function(djangoRMI){ return {getData:getData}; …
AncientSwordRage
  • 7,086
  • 19
  • 90
  • 173
0
votes
1 answer

Testing angular factory with promise

I have the below service that i am trying to write some unit test using jasmine, i am using $http.get that returns a promsie. How should i test this. myApp.service("authorService", function ($http, $q, $timeout) { return { getAuthors:…
user804401
  • 1,990
  • 9
  • 38
  • 71
0
votes
1 answer

Angular Mocks breaking my application

I want to use angular-mocks.js in my application. I have the script dependency referenced in the and want to include it as a dependency for my module: angular.module('myapp', ['ngMock']); Before adding ngMock to my module, all of the…
UltraSonja
  • 881
  • 1
  • 20
  • 33
0
votes
1 answer

AngularJS : $httpBackend regex pattern to pass through requests for certain URL pattern

I am using ngMockE2Efor mocking some of my services. I want to pass through all the requests which has /app in the requests. how can I specify this condition in regex? For example app/assets/server/a.json this URL should not be mocked and it has to…
JPS
  • 2,730
  • 5
  • 32
  • 54
0
votes
1 answer

How to check if location is changed and controller loaded

I'm trying to write a unit test for a controller that does a POST then changes page. How can I check if a path is loaded and the controller for that path is loaded?
el_pup_le
  • 11,711
  • 26
  • 85
  • 142
0
votes
0 answers

unit test $location.path().search method

I have a directive called clickElement: function clickElement( $location) { var clickElementDefinition = { restrict: 'A', scope: { clickElement: "=" }, …
user2439903
  • 1,277
  • 2
  • 34
  • 68
0
votes
0 answers

I can't use my scope variable while testing

I can't use my variable $scope.films in my test with karma and I don't have any idea from where am I fail : filmsService.js : (function () { 'use strict'; var filmsServices = angular.module('filmsServices', ['ngResource']); …
0
votes
0 answers

AngularJs unit test: "Unsatisfied requests: DELETE"

Getting "Unsatisfied requests: DELETE" for my controller test. below are the code for my service, controller and test. tests are written using jasmine-karma and angular-mock. Thanks in advance. service: function deleteAsset(assetId) { return…
0
votes
2 answers

Testing Angular requests

Having a problem figuring out how to test an $http request on a factory. Basic factory: angular.module('myServices', []) .factory('myFactory', function($http) { return { postLog: function(logData) { …
diplosaurus
  • 2,538
  • 5
  • 25
  • 53
0
votes
1 answer

Unable to get Mocha and Angular mocks to work in Plunker

I am trying to show an example of mocha in plunker but it is giving me angular mocks undefined issues. I tried copy and pasting bower angular mocks to no avail. beforeEach(function(){ angular.mock.module('plunker'); }); Errored code from…
technoSpino
  • 510
  • 4
  • 12
0
votes
0 answers

How do I invoke a factory constructor with angular.mocks.inject?

Consider this code: beforeEach(inject(function (_User_) { user = _User_; })); And this module/service: angular.module('app.userModule', []) .factory('User', function() { function User(data) { data.forEach(function (attr) { …
NewToMS
  • 65
  • 10
0
votes
0 answers

AngularJS Mocking

I've got no idea what's happening here. I'm trying to mock out a service and inject it inside a controller. My first test passes but then my second test gives the following error: Error: [ng:areq]…
K-Dawg
  • 3,013
  • 2
  • 34
  • 52
1 2 3
13
14