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

typescript importing wrong angular

I am importing angular in my angular 1 app (in typescript) using syntax like below import * as angular from 'angular'; This imports angular from angular-mocks and not from angular because of which my ILogService implementation fails ERROR in…
harishr
  • 17,807
  • 9
  • 78
  • 125
6
votes
7 answers

TypeError: angular.element.cleanData is not a function

I'm getting the following error in my karma unit test when trying to use inject() Example ✗ should wait for promise to resolve and have a result Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test. …
chovy
  • 72,281
  • 52
  • 227
  • 295
5
votes
2 answers

How to test angularjs component with DOM

I am trying to get familiar with testing an AngularJS application. While testing component logic is clear more or less, I have a trouble with html templates and model binding, because I'd like to test html binding together with controller's…
Daniil Iaitskov
  • 5,525
  • 8
  • 39
  • 49
5
votes
3 answers

what's the correct way to import angular-mocks

Versions typescript: 2.1.4 systemjs: 0.19.41 angular: 1.5.10 angular-mocks: 1.5.10 Problem I'm trying to load angular-mocks with systemjs in a typescript 2.0 project. If i use the following it works, but i get a TS error and {module} is also marked…
james
  • 4,150
  • 2
  • 30
  • 36
5
votes
1 answer

Testing $interval in Jasmine/ Karma

I have a simple factory angular.module('myApp.dice',[]).factory('Dice', ['$interval', function($interval){ return { rollDice: function(){ return $interval(function(c){ count++; }, 100, 18, false, 0); …
Kendall
  • 5,065
  • 10
  • 45
  • 70
5
votes
2 answers

Mock document.getElemetById('.form').getContext('2d') using sinon

I'm using karma, mocha, chai, sinon and Angular mocks for my unit testing. In my $scope.loadChart, I'm drawing a chart in my canvas tag. I'm using http://www.chartjs.org/ to draw the charts. Chartjs requires this piece of code,…
Norbs Knight
  • 169
  • 2
  • 10
5
votes
1 answer

How do I mock $window injected manually in provider private function?

I have the following provider: angular.module('MyApp').provider('MyDevice', function () { var ngInjector = angular.injector(['ng']), $window = ngInjector.get('$window'); function isMobileDevice () { return…
rfgamaral
  • 16,546
  • 57
  • 163
  • 275
5
votes
2 answers

Match all GET url using angular-mocks for backendless

I am writing a frontend without backend ajax for now. I am using angular-mocks to simulate API call like this: $httpBackend.when('GET', '/somelink').respond(function(method, url, data) { //do something }); However, if the ajax passes params:…
HP.
  • 19,226
  • 53
  • 154
  • 253
4
votes
1 answer

Mocking rest calls in functional e2e protractor tests in angular 4 project

We have a huge project and we have written a lot of test cases to cover a lot of real scenario user behavior in our e2e functional test cases. As the test goes on, it makes a lot of rest calls to complete the test cases. When we cover different…
Aniruddha Das
  • 20,520
  • 23
  • 96
  • 132
4
votes
1 answer

Unit test component angular

I am trying to unit test my component controller and I am getting following errors. Can anyone tell me, what's wrong here? My dependencies: angular 1.5.6 angular-mocks 1.5.7 mocha 2.5.3 karma 0.13.22 Errors: modalCleanup component "before all"…
Vitaly
  • 125
  • 2
  • 9
4
votes
2 answers

How to unit test (using Jasmine) a function in a controller which calls a factory service which returns a promise

In the below SampleController, how do I unit test that postAttributes function calls sampleService.updateMethod. I'm having trouble since the updateMethod returns promise. angular.module('sampleModule') .controller('SampleController',…
4
votes
2 answers

Accessing $http data in Protractor / E2E tests (AngularJS)

I have a bunch of Unit tests that are going well, and I've started to add Protractor E2E tests to my project. I'm doing okay testing interactive elements on the page, but I'm having trouble testing for certain data being sent out of the…
diplosaurus
  • 2,538
  • 5
  • 25
  • 53
4
votes
1 answer

Create unit tests where each test has its specific test data and test mocks

I have this test structure and it is working but It does not cover my requirements when I put more tests in this unit test .js file , but all related tests should go there. WORKING: 'use strict'; describe('lessonplannerFactory unit tests', function…
Pascal
  • 12,265
  • 25
  • 103
  • 195
4
votes
0 answers

Unknown provider: $rootElementProvider <- $rootElement <- $location error in karma run

hi i am getting the error while running karma run controller : myApp.controller('LookupCtrl', function($scope, $rootScope, LCService, $q, $http,$location) {....} Here the above controller users LCService LCService :…
user2696439
3
votes
1 answer

How can I unit test the result of a ui-bootsrap $uibModal instance?

I have a controller that calls $uibModal.open to pop a ui-bootstrap modal. The controller looks like this: (function () { 'use strict'; angular .module('app') .controller('MyCtrl', myCtrl); function myCtrl($uibModal) { …
stephen776
  • 9,134
  • 15
  • 74
  • 123
1
2
3
13 14