The official Angular quickstart is not able to run karma tests after a clean install on Windows 10. I typed the following 4 commands and nothing else: C:\projects\temp>git clone https://github.com/angular/quickstart.git C:\projects\temp>cd C:\projec
I have been struggling with this for a while, and I'm hoping someone can help. I have a component that uses a service to get data. I am attempting to add unit tests to it. My problem is that the tests always fail with "Error: No provider for Http&quo
I have below code in abc controller: $rootScope.$on('selectedItem', function (event, data) { vm.selectedItem = data; }); And the caller function is in xyz controller: function doThis(){ $rootScope.$emit('selectedItem', 'somedata'); } How can I reprod
I am a beginner of angular2. My service.ts will be, import { Injectable } from '@angular/core'; import { Http, Response } from '@angular/http'; import {Headers, RequestOptions, URLSearchParams} from '@angular/http'; import {Observable} from 'rxjs/Obs
I have the following simple Jasmine test... //test.spec.ts describe('Sample', function(){ it('Should do something', () => expect(true).toBe(true)); }); But when I run I get... Error: 'expect' was used when there was no current spec, this could be bec
I am testing an angular service method with $httpBackend and trying to mock different responses based on the request data. The problem is, if I send the error status if request is invalid, it still calls the success callback of $http method, thus I a
When do you use the async function in the TestBed when testing in Angular 2? When do you use this? beforeEach(() => { TestBed.configureTestingModule({ declarations: [MyModule], schemas: [NO_ERRORS_SCHEMA], }); }); and when do you use this? beforeEach
I am starting to test a service in Angularjs with Karma and Jasmine. I have no idea how $q works, i have never use it and anyway i do not know if it is necessary here. My problem is that I have a service which have 1 function which calls another func
I am trying to test user search functionality inside an angular custom component. The input (and only input) in the directive template that I am trying add text to and trigger the search is: <input type="text" ng-model="searchInput"
I have the following code in my spec file beforeEach(function () { module('app'); inject(function ($injector) { user = $injector.get('app.user'); }); }); user is undefined, and isn't being injected. So I want to make sure that the app module actually
This question already has an answer here: Jasmine JavaScript Testing - toBe vs toEqual 4 answers I am using Jasmine karma test case for a while and found tests failing sometime because of using .toBe() instead of .toEqual(). What is the difference be
I am developing an Ionic app. The calling function lets the user call the number in factory.call. factory.call = '345-678-9087'; factory.calling = function(){ return $window.location.href = 'tel:' + factory.call; }; This is the Jasmine test for the a
I am trying to run this spec and I got this error: SyntaxError: import declarations may only appear at top level of a module But as you see I have the import on top, so there's could be another reason for this? ng-form-builder.spec.js import angular
I'm building some unit tests for a service in Angular2. Within my Service I have the following code: var hash: string; hash = this.window.location.hash; However when I run a test which contains this code, it will fail. It'd be great to utilise all th
Whenever, I am testing a controller and have something like this in it. $scope.isSomething = function (Item) { return ItemCollection.someItem(Item.attachedItem); }; giving error on karma console: TypeError: undefined is not an object (evaluating 'Ite
I am new to unit testing and I am getting these errors even though I though my test was correct, I just cannot figure out what these errors mean and I have tried several things Can't find variable: $rootScope Error: Injector already created, can not
I'm new to Unit Testing so I only got to know Jasmine and Karma today. I installed Karma: npm init npm install karma --save-dev npm install -g karma-cli npm install karma-jasmine --save-dev npm install karma-chrome-launcher --save-dev karma init Howe
I'm writing Jasmine Unit test for AngularJS UI grid. I have a below UI grid function in my controller Code: $scope.gridOption.onRegisterApi = function(gridApi) { $scope.gridApi.core.on.sortChanged($scope, function(grid, sortColumns) {}; gridApi.pagin
I am new to jasmine and stuck at few places while mocking the functions. How to mock angular global functions such as angular.forEach(), angular.isDefined(), angular.isUndefined().I typically wouldn't mock these functions as they are so simple - I th
I'm using Karma and Jasmine for testing my Angular JS code. I managed to run all the tests in my project using Karma, but if I try to run just a single file I'm getting the following error: ReferenceError: describe is not defined. Is it possible to r
I have a directive which is declared as an Attribute: app.directive('myDirective', function() { return { restrict: 'A', replace: true, transclude: true, scope: { data: "=" }, template: '<p class="my-paragrapgh">' + '<label>
In a Jasmine test, I am trying to set this match to fit with expressions like: 'Request <any_word> for <any_word> - Open actions menu'. However, it's not being possible with this line, but Javascript doc says that \\w is the regex for any word
I have a directive that look like this: angular.directive('myDirective', ['$window', function($window){ return function (scope, element) { var w = angular.element($window); var top = element.offset().top-w.scrollTop(); function adjustTop(){ var oldto
So, I've been looking all over for this, found "similar" answers here, but not exactly what I want. Right now if I want to test a single file with karma, I need to do fit(), fdescribe() on the file in question... However, what I do want is to be
I've created a JHipster project and created a javascript spec, however when I run karma start I'm getting this output: ~/projetos/consami/src/test/javascript$ karma start INFO [karma]: Karma v0.12.31 server started at http://localhost:9876/ INFO [lau
I am writing test cases using AngularJS with Jamsine. Working on mobile application using AngularJS and for UI using IONIC framework. So I am calling one of controller function from my spec.js for testing. Meantime, I am getting error like. Error: Un
My Angular 1.3 application is using the angular-translate library. In my Karma tests I'm attempting to mock the $translate provider with a Mock object I have created. The mock object is called MockTranslate and it belongs to the myMocks module. I'm n
I'm having trouble testing my directive with an ng-mouseenter directive. I'd like to test several things, but first off, I need to test that the method supplied to ng-mouseenter is called. my test: describe('hover tests', function () { it('the trigge
I am using controller to change the class of an object in angularjs $scope.$watch('sideQuery',function(){ if($scope.sideQuery==""){ $(".indicator").removeClass('glyphicon-minus'); $(".indicator").addClass('glyphicon-plus'); }
I created an angular app with yoeman scaffolding tool, using the command: yo angular when I run grunt serve it outputs my app fine, its when I run grunt that I get Running "karma:unit" (karma) task ERROR [config]: File /home/ubuntu/karma.conf.js