The angular quick start fails the karma test out of the box

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

Unit testing and simulation of a service with DI

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

How can I test $ rootScope. $ Emit event?

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

Angular2 - HTTP call unit test

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

Jasmine test simple typescript start "wait" error

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

Angular 2 Testing - Asynchronous function call - when to use

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

Test a service with a promise in Angular with Karma-Jasmine

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

Simulate Enter Key Press Enter in Karma / Jasmine tests

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"

Test the return value of a spy

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

Karma problem Javascript import SyntaxError

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

Testing a controller with a specific syntax

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

Can not find variable: $ rootScope

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

Karma-jasmine does not install

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

Jasmine test case for angular

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

How to run a single test file with Karma / Jasmine?

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

The unit test fails when the directive is an attribute

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>

Javascript Regex: & ldquo; Any word & rdquo; model

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

AngularJS - Unit Test with Windows Scroll

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

Karma: Running a single test file from the command line

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

Why karma does not run any tests?

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

Unit tests using the Jasmine project and Karma / AngularJS

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

How to make fun of a supplier

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

Jasmine test for ng-mouseenter

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

css testing in angularjs

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'); }

karma.conf.js does not exist! Nodejs error

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