FAQ Database Discussion Community


expected scope variable undefined in karma test

javascript,angularjs,unit-testing,karma-runner
I'm having trouble understanding how the scope gets initialized in karma tests. i'm expecting a scope variable to be preset when the test runs, but it keeps coming back as undefined. What am I missing? Test Case describe('loginController', function() { beforeEach(module('app')); var $controller, $scope; beforeEach(inject(function(_$controller_, $rootScope){ $controller = _$controller_; $scope...

AngularJS, Mocha, Karma. testing controller, mocking service promise

angularjs,promise,mocha,karma-runner,chai
I'm using AngularJS, Karma, Mocha, Chai, Chai-as-promised, Sinon. I'm trying the controller below. I am having trouble mocking the service User and test the .then() sections in the controller. Controller Code .controller('SignupPhoneCtrl', function(User, $scope) { $scope.sendPhoneNumber = function(countryCode, phoneNumber){ User.sendPhoneNumber(countryCode, phoneNumber) .then(function(result){ if(result == "success"){ //I WANT TO TEST THIS...

Getting Karma, 6to5ify and Istanbul to play ball

code-coverage,karma-runner,browserify,ecmascript-6,karma-coverage
I have Browserify, 6to5ify and Karma to play nice, successfully running my specs. When I add code coverage however, things go south. I've tried several approaches: Add browserify-istanbul transform to my karma.conf.js. However, this results in it trying to run instrumentation on my spec-files as well it would appear. Run...

Angular test using $httpBackend fails with “400 thrown” error

angularjs,karma-runner,karma-jasmine,httpbackend
For hours I've been trying to test my NewPostController with $httpBackend. The problem is whenever I set non-2xx status code in the response, the test fails. NewPostController has the following method: $scope.submit = function () { var newPost = $scope.newPost; PostService.insertPost(newPost).then(function (post) { $location.path("/my-posts"); }, function (status) { $scope.form.$setPristine(); $scope.error...

karma.conf.js automatic file ordering?

angularjs,jasmine,phantomjs,karma-runner,karma-jasmine
I have a large angularjs project ordered by features. I'd like to setup unit testing but I'm having trouble getting the karma.conf.js file ordering setup. I tried specifying a simple glob pattern like **/*.js but many of my modules failed to load due to the ordering that they're included in...

How can I unit test a promise chain with Karma?

javascript,promise,karma-runner
My controller code has: save: function () { var that = this; patientCache.saveCurrentPatient().then(function(){ return adherenceCache.updateAdherenceSchedule(that.model.patientId) }).then(function () { that.buildAdherenceUrl(); }); }, I want to test patientCache.saveCurrentPatient(), adherenceCache.updateAdherenceSchedule and that.buildAdherenceUrl are called. This is my test: beforeEach(function() { module('mapApp'); return inject(function($injector) { var $controller, $rootScope; $rootScope = $injector.get('$rootScope'); $controller =...

Gulp task not accessing karma.conf.js file

javascript,node.js,gulp,karma-runner,gulp-karma
I am using following gulp task to execute the karma/jasmine unit test cases . however i was not able access the karma.conf.js file for some reason. this problem occurs when i use this pathpackage to access the karma.conf.js file. gulp task gulp.task('tdd', function (done) { karma.start({ configFile: fs.readFile(path.join(__dirname, '../Tests/karma.conf.js')), singleRun:...

Testing a class was added or removed with karma for an angularjs app

angularjs,jasmine,karma-runner
I am trying to write some unit tests for an angularjs app using karma/jasmine. The part I'm hung up on is testing that a class was successfully added/removed. The function I am trying to test: vm.toggleMenu = function toggleMenu(prev) { if(angular.element('menu').hasClass('hide')) { if(prev) { angular.element('#view').removeClass('col-md-8').addClass('col-md-12'); } else { angular.element('menu').removeClass('hide'); angular.element('#view').removeClass('col-md-12').addClass('col-md-8');...

No provider for framework require.js

karma-runner
when i try to start karma i am getting error below: C:\*>karma start karma.conf.js C:\Users\*\AppData\Roaming\npm\node_modules\karma\node_modules\di\lib\injector.js:9 throw error('No provider for "' + name + '"!'); ^ Error: No provider for "framework:jasmine"! (Resolving: framework:requirejs) at error (C:\Users\*\AppData\Roaming\npm\node_modules\karma\node_modules\di\lib\injector.js:22: at Object.parent.get (C:\Users\*\AppData\Roaming\npm\node_modules\karma\node_modules\di\lib\inj at get...

AngluarJS Unit Test - Undefined is not a function

javascript,angularjs,unit-testing,jasmine,karma-runner
I am trying to learn how to unit test within angular. Unit testing my controllers to start with then my services. I have started off with a basic test. Controller code: angular.module('app') .controller('TestCtrl', function ($rootScope,$scope,fileLoader,ngProgress) { $scope.test= []; $scope.init = function(){ fileLoader.getFile("test") .then(function(res){ //Success console.log(res); $scope.test= res; }, function(err){ //Error...

Is Karma Tast Runner working on node js v0.12.0?

javascript,node.js,unit-testing,gulp,karma-runner
I use node.js v0.12.0 and i have installed karma to my OS X Yosemite but when i run my test task with gulp it waits like in the picture. It doesn't start PhantomJs. I tried the same code in node version of v0.10.32 and it works but it doesn't work...

How to mock $scope.variables in jasmine

angularjs,unit-testing,jasmine,karma-runner,karma-jasmine
I have the following test case CompanyCtrlSpec.js describe('ViewCompanyCtrl', function () { var $rootScope, scope, $controller , $q ; beforeEach(angular.mock.module('MyApp')); beforeEach(inject(function ($rootScope, $controller ) { scope = $rootScope.$new(); createController = function() { return $controller('ViewCompanyCtrl', { $scope: scope, company : {} }); }; })); it('the company type should be equal to an...

Spy on a service method call using jasmine Spies

angularjs,unit-testing,jasmine,karma-runner,karma-jasmine
I have the following controller ViewMeetingCtrl.js (function () { 'use strict'; angular.module('MyApp').controller('ViewMeetingCtrl', ViewMeetingCtrl); ViewMeetingCtrl.$inject = ['$scope', '$state', '$http', '$translate', 'notificationService', 'meetingService', '$modal', 'meeting', 'attachmentService']; function ViewMeetingCtrl($scope, $state, $http, $translate, notificationService, meetingService, $modal, meeting, attachmentService) { $scope.meeting = meeting; $scope.cancelMeeting = cancelMeeting; function cancelMeeting(meetingId,...

How to inject a service to jasmine

angularjs,unit-testing,jasmine,karma-runner,karma-jasmine
I have the following test case MeetingCtrlSpec.js describe('ViewMeetingCtrl', function () { var $rootScope, scope, $controller ; beforeEach(angular.mock.module('MyApp')); beforeEach(inject(function ($rootScope, $controller ) { scope = $rootScope.$new(); $controller('ViewMeetingCtrl', { $scope: scope, }); })); it('should change greeting value if name value is changed', function () { //some assertion }); }); ViewMeetingCtrl.js (function ()...

AngularJS ReferenceError: module is not defined

javascript,angularjs,karma-runner
This is the error message I am getting when I run Karma. it says it is happening at controllerTest.js:13 below are lines 1 to 4: describe('forgotPasswordCtrl', function() { beforeEach(module('forgotPasswordApp')); var $controller; var returnMsg = 'Forgot password response message'; so I believe it is the beforeEach part. no idea why it...

Cannot get karma test to pass on controller

javascript,arrays,angularjs,karma-runner
I'm trying to create a "To Do list" in angular js. Upon completing a task, I want to be able to click on a checkbox to mark for completion. Although it is working on the index.html, I cannot get the test itself to pass. This is my test: describe('ToDoListController', function()...

Karma not starting phantomJs

angularjs,node.js,phantomjs,gulp,karma-runner
I'm loosing my mind here. I have a gulp task that looks like this. var gulp = require("gulp"); var karma = require("karma").server; gulp.task("test", function (done) { karma.start({ configFile: __dirname + "/karma.conf.js", action:"run" }, function () { done(); }); }); My karma.conf.js looks like this: module.exports = function (config) { config.set({...

Why am I getting message that provider must return value from factory $get method?

angularjs,jasmine,karma-runner
So, I have a suite of tests for angular, using jasmine and karma. I have a module for lodash and moment defined like this (function (angular) { var lodash = angular.module('lodash', []); lodash.factory('_', ['$window', function ($window) { //lodash must already be loaded on the page var _ = $window._; delete...

Supress console logs from code being tested

jasmine,karma-runner,karma-jasmine
I'm unit testing a function which contains a console.log() call. How can I prevent the output of that call from being displayed in the output console of my test runner, in this case, Karma. I'm using Jasmine. I'm looking for a more elegant way than overriding browser's console methods, preferably...

Difference between browser().location().url() and browser().window().href() in Jasmine?

jasmine,karma-runner,karma-jasmine
Does anyone have ideas about the difference between browser().location().url() and browser().window().href() ? Thanks!...

ES6 - how to test Jasime tests thru karma using ES6 like 'import' statement

jasmine,karma-runner,browserify,traceur,gulp-karma
I am new to javascript, trying to write a spec having an ES6 like import statement and then execute it thru Karma with pre-processors as traceur and browserify (to bundle and provide 'require' method). It continues to give me an error of invalid syntax and on looking at the specs...

How to invoke spyOn on a scope function

angularjs,unit-testing,jasmine,karma-runner,karma-jasmine
I have the following jasmine spec. describe('ViewMeetingCtrl', function () { var $rootScope, scope, $controller , $q ; beforeEach(angular.mock.module('MyApp')); beforeEach(inject(function ($rootScope, $controller ) { scope = $rootScope.$new(); createController = function() { return $controller('ViewMeetingCtrl', { $scope: scope, meeting : {} }); }; })); it('the meeting type should be equal to an object',...

Angular Karma Test getting “TypeError: 'undefined' is not a function”

javascript,angularjs,karma-runner,karma-jasmine
Controller dashboardApp.controller('ExecutiveController', ['$scope', 'ExecutiveService', function ($scope, executiveService) { executiveService.getDashboardData().then( function success(response) { $scope.productsInfo = response.data; }, function error(reason) { console.log(reason); }); } ]); Test case for Controller 'use strict'; describe('ExecutiveController', function () { var scope, ctrl, mockService, $timeout; beforeEach(module('do.dashboard')); beforeEach(inject(function ($rootScope, $controller, $q, _$timeout_) { mockService =...

How to automate karma unit tests with continuous integration

node.js,unit-testing,continuous-integration,karma-runner,circleci
Currently we run our karma/jasmine unit tests a gulp task: gulp test We are trying to figure out how to get circleci to run our tests automatically. I tried adding gulp test under the test: section of the circle.yml file but I get gulp: command not found. But I get...

Using $injector in AngularJS when integration testing (without using ngMock)

angularjs,unit-testing,jasmine,integration-testing,karma-runner
I'm needing to setup some integration tests in AngularJS using Karma/Jasmine but having trouble, because when not using ngMock (since I want to hit the actual $http endpoints), there are no module or inject methods. So how do I inject services into my tests? I've tried angular.injector.invoke(...) but can't get...

Angular module test not working

angularjs,unit-testing,mocha,karma-runner
I am trying to test an angularjs app. I managed to get some basic test running on my laptop. These tests just check for a module and check some basic functions. This works fine on my laptop. However when I move the testing environment to a local server the tests...

Angular, Sinon, promises

angularjs,unit-testing,mocha,karma-runner,sinon
Can't get my head around angular, sinon and promises. If I need to test something like this: myCtrl.js angular.module('app') .controller('myCtrl', ($scope, dataService)=> { dataService.list('location').then((lst)=> { $scope.list = lst; }); }); myCtrl-spec.js describe('testing controller', ()=> { var locations = ['A','B','C'], dataService, $scope; beforeEach(module('app')); beforeEach(inject($controller, $rootScope, _dataService_, $q) => { dataService =...

No binary for PhantomJS browser on your platform. Please, set “PHANTOMJS_BIN” env variable

phantomjs,karma-runner,mocha-phantomjs,karma-mocha,karma-coverage
My package.json looks like this.. "karma-phantomjs-launcher": "^0.1.4", "karma-safari-launcher": "^0.1.1", "karma-sinon-chai": "~0.2.0", "karma-spec-reporter": "~0.0.16", "mocha": "~1.20.1" my npm version is 2.2.0 whay am I getting this when I run karma test - karma start my.conf.js...

lodash npm distribution in browser

npm,karma-runner,bower,lodash
I'm using lodash in my tests, Not using webpack or browserify (don't need to). I found that the default npm build differs from what's in bower. I could of course use bower version, but I'm curious if I can use npm's instead (it's already there for Gulp). For bower I...

Karma + Angular undefined error

javascript,angularjs,unit-testing,karma-runner,karma-jasmine
I just started angular testing with karma and jasmine. I've written two basic tests. One of the two tests pass, but the other one is failing. I can't seem to debug it. I've been looking everywhere, and it should work according to various tutorials. The $scope variable should be available....

No longer able to use ddescribe or iit

javascript,jasmine,karma-runner
I used to be able to use ddescribe and iit to have jasmine/karma run just a specific test or set of tests. However, now it no longer works, and I get this error: (or a similar one for iit). INFO [karma]: Karma v0.12.31 server started at http://localhost:8081/ INFO [launcher]: Starting...

Reusing angular mocks in Jasmine tests using $provide

angularjs,testing,mocking,jasmine,karma-runner
I wish to reuse my mocks instead of having to set them up in every unit test that has them as dependency. But I'm having a hard time figuring out how to inject them properly. Here's my attempt at unit test setup, which of course fails because ConfigServiceMockProvider doesn't exist....

React's TestUtils.Simulate.keyDown does not work

javascript,node.js,reactjs,karma-runner
I have a lot of components in my application that respond to different key presses, and so far, none of my tests that use TestUtils.Simulate.keyDown work at all. It seems like keyDown just plain and simple does not work. Here's the component I'm trying to test: description.js var React =...

Speed up tests run in Chrome

javascript,osx,google-chrome,karma-runner
This is based on this question where it was discovered that when Chrome is not in the foreground, the tests run really slow. Anyone know how to get around that so I can continue to use Chrome, but don't have to keep it in the foreground?

Karma exits with code 1 when it doesnt execute any spec tests

karma-runner,karma-jasmine,gulp-karma
Karma test runs fine but exits with code 1 if 0 of 0 tests are run. Does anyone know how to return exit code 0 and normally exit in this case? Using gulp-karma which fails the task when no specs are run.

Mock the value of a service inside directive's unit test

angularjs,unit-testing,jasmine,karma-runner
Inside my directive's instantiation I have a call to a method that returns some data: data = myService.getData() and later in the code I am doing something = data[id] In karma I have an error, cannor read id of undefined, meaning that data is undefined. I tried to mock the...

Ajax : empty json response when using Karma

jquery,ajax,json,firefox,karma-runner
TL;DR : Does Karma temper with ajax request sent while running tests ? Context I'm currently writing unit-tests for a front-end javascript application. I'm using Karma 0.12.31 to run the tests and the only frontend library I use that is relevant to this question is jQuery. I have a really...

Accessing scope.variables inside a function in jasmine

angularjs,unit-testing,jasmine,karma-runner,karma-jasmine
I am trying to get the assert the value of the $scope.buttonDisable variable which is inside the save(). here is the test case describe('EditMeetingCtrl.save()', function () { var $rootScope, scope, $controller , $q , state , controller ; var companyService , meetingService ; beforeEach(angular.mock.module('MyApp')); beforeEach(angular.mock.inject(function (_$httpBackend_, _companyService_ , _meetingService_ )...

Problems with $httpBackend.verifyNoOutstandingExpectation()

jasmine,karma-runner,karma-jasmine,jasmine-node
I have recently started writting unit tests using Karma + Karma-jasmine but I am having problems with the following tests: describe("WEBSERVICE:", function () { var webservice, $httpBackend, authRequestHandler, webserviceURL = "http://localhost:8006/"; beforeEach(inject(function (Webservice, $injector) { webservice = Webservice; $httpBackend = $injector.get("$httpBackend"); authRequestHandler = $httpBackend .when("GET", webserviceURL + "users/login") .respond(200, "ok");...

Karma testing lodash Factory

angularjs,jasmine,karma-runner,karma-jasmine,lodash
i have created a factory for the lodash library in my angular app like so: angular.module('lodash',[]).service('_', function(){ var _ = window._; // i am delete the _ property on the window // so that i m enforced to dependency inject // lodash each time i want to use it //...

How to avoid long relative paths (../../../) with jasmine in different environments?

node.js,testing,jasmine,karma-runner,browserify
I am currently developing a project, which I want to test in different environments - including node.js and different browsers with karma/selenium - to avoid compatibility issues. (I think I will use browserify in browsers, but I am not familiar with it yet.) I have a nested testing directory, something...

Unit testing AngularJS Controller whilst following best practice

javascript,angularjs,unit-testing,karma-runner,karma-jasmine
We are building an AngularJS app following some of the best practice guidelines which are outlined here. Am specifically interested in testing a very simple controller to get up and running with karma. The controller code is: angular.module('ttn').controller('Login', Login); function Login(){ var login = this; login.title = 'foo bar content...

TypeScript Compile Suggestions (TS + gulp + karma)

typescript,gulp,karma-runner
I am trying to come up with a viable TypeScript build step that includes the following: Compile TypeScript (obviously) ideally allowing the compiler to traverse the dependency tree Execute jasmine unit tests via karma No dependencies on IDE's (Visual Studio/WebStorm) to execute tests and output JS Ability to execute unit...

how to fix images causing “karma WARN [web-server]: 404”?

karma-runner,karma-jasmine
I have an angular directive with a template that is doing something like: <img ng-src="{{url}}" /> In my test, I am setting the scope so that url points to a fictitious image... Karma then says: WARN [web-server]: 404: /fake.png So I go into my karma config file and add to...

Angular Karma test not running properly, gives error “Argument 'fn' is not a function, got undefined”

javascript,angularjs,jasmine,karma-runner,karma-jasmine
I'm trying to add unit tests to an angular controller using karma but I've run into an issue and I need some help. I've found similar questions asked here but none have led me to an answer. I've tried changing the order of the "files" array in the karma.conf.js thinking...

Asynchronous tasks in grunt.registerTask

gruntjs,karma-runner
I need to call two functions within grunt.registerTask, but the second function has to be called after the first function is done. So I was wondering if we can use callbacks or promises or other asynchronous mechanisms within grunt.registerTask. (More specifically, I need to launch karma in my first function...

RegeneratorRuntime is not defined

javascript,karma-runner,babeljs,karma-babel-preprocessor
I am trying to run Karma-babel-preprocessor and a straight forward ES6 generator: //require('babel/polyfill'); describe("how Generators work", function() { it("will allow generator functions", function() { /*function * numbers() { yield 1; yield 2; yield 3; };*/ let numbers = { [Symbol.iterator]:function*(){ yield 1; yield 2; yield 3; } } let sum...

Setting up Jasmine/karma for angular

javascript,angularjs,jasmine,karma-runner
I am lightly following this guide - http://paislee.io/testing-angularjs-with-grunt-karma-and-jasmine/ - and having a few issues as follows: Error: [$injector:modulerr] Failed to instantiate module myApp due to: Error: [$injector:modulerr] Failed to instantiate module ngRoute due to: Error: [$injector:nomod] Module 'ngRoute' is not available! You either misspelled the module name or forgot to...

Nodejs : peerDependencies error while installing depedencNodejs

node.js,npm,karma-runner,karma-jasmine
In my attempt to get the libraries I need, npm install was working well till about a year and now as I move to a new server it breaks stating PeerDependencies error. I am kind of confused as I fail the reason for which the code is breaking, has any...

Karma unit test 'undefined' is not a function error

javascript,angularjs,unit-testing,karma-runner
I have a custom directive for checking if values in two input fields are equal to each other (repeat password) which I want to test. It works fine but test fails with this error: TypeError: 'undefined' is not a function (evaluating 'element.add(tween)') The directive is very simple and straightforward: angular.module('fmAppApp')...

display karma tests on browser

angularjs,unit-testing,karma-runner,karma-jasmine
I'm new to karma unit-testing angular. I tested angular-socket-io application. This is what I saw when I ran karma start on the console. 21:58 /tmp/angular-socket-io $ karma start INFO [karma]: Karma v0.10.10 server started at http://localhost:9999/ INFO [launcher]: Starting browser Chrome INFO [Chrome 40.0.2214 (Mac OS X 10.8.3)]: Connected on...

Inconsistent behaviour with browserstack testing of ReactJS via travis-ci vs localhost

jasmine,reactjs,karma-runner,travis-ci,browserstack
I'm running test towards browserstack with karma (karma-browserstack-launcher, browserify + reactify), using jasmine as test suite with my reactjs code, and I'm getting inconsistent behaviour. If I run karma start karma.conf from my laptop (using Chrome 39 on windows 8.1), every test runs fine, but if I the command is...

How to ignore a run.js in Angular / Karma unit testing?

javascript,angularjs,unit-testing,karma-runner
I have a file run.js that has: window.map.run([ '$rootScope', '$location', 'cache', 'userCache', function($rootScope, $location, cache, userCache) { userCache.checkSession().then(function(result) { if(result.userId) { cache.set('login', 'successfulLogin', true); if($location.path() !== '/patients') { $location.path('/patients'); } } }); } ]); This runs when the app loads. This is normally great behavior. But when I'm unit testing...

How to inject angular value and angular constant into karma unit test?

javascript,angularjs,unit-testing,karma-runner,yeoman
I want to test this controller /controllers/datetimepicker.js angular.module('c2gyoApp') .value('smConfig', { rate: 'A', tariff: 'classic' }) .controller('DatetimepickerCtrl', [ '$scope', 'stadtmobilRates', 'smConfig', function($scope, stadtmobilRates, smConfig) { ... $scope.getCurrentRate = function(rate, tariff) { // studi and classic have the same rates if (tariff === 'studi') { tariff = 'classic'; } return stadtmobilRates[tariff][rate]; };...

Can I use karma to launch a test server?

testing,karma-runner,karma-mocha
I have setup testing locally using Karma, Mocha and Chai, whenever I run karma start I get a webserver running locally: INFO [karma]: Karma v0.12.31 server started at http://localhost:9876/ I can then go to http://localhost:9876 using any browser I have and see how my tests run on that browser. Is...

Unit testing with Karma on an Angular 1.3/JSPM/Babel project

angularjs,karma-runner,ecmascript-6,jspm
So I'm setting up an angular 1.3 es6 project using jspm and babel. Im using es6's import/export feature. I have karma and karma-jspm installed and can run basic tests without an issue. When I try to import one of my modules into a test to test it, I get an...

WebStorm - Jasmine jQuery

jquery,unit-testing,karma-runner,webstorm,karma-jasmine
I'm quite new to the usage of WebStorm, but it's not working as epected. I had a project in the past, but now I try to recreate it and try to unit test my code. I'm very new to unit testing JavaScript code. So, I have a file karma.conf.js which...

AngularJs Test, change a variable to cover an if else block

angularjs,karma-runner,chai
I have a controller I need to test; coverage is crucial for me... This is my full code from controller: terminalController.controller('CashAcceptorController', [ 'PaymentService', '$rootScope', '$scope', 'PayingInfo', '$interval', '$location', function (PaymentService, $rootScope, $scope, PayingInfo, $interval, $location) { $rootScope.currentPage = 'CASH_ACCEPTOR'; var number = ''; if ($rootScope.serviceNumber == 'm1') { number =...

how to mock $state.params in jasmine unit testing

angularjs,unit-testing,jasmine,karma-runner,karma-jasmine
I have the following controller EditMeetingCtrl.js (function() { 'use strict'; angular .module('myApp') .controller('EditMeetingCtrl', EditMeetingCtrl); EditMeetingCtrl.$inject = ['$rootScope', '$scope', '$state', '$http', '$translate', 'meetingService', 'companyService', 'notificationService', 'meeting']; function EditMeetingCtrl($rootScope, $scope, $state, $http, $translate, meetingService, companyService, notificationService, meeting) { $scope.meeting = meeting; $scope.companyId = $state.params.companyId; $scope.save = save; function...

AngularJS Karma testing “Error: Unexpected request: GET” doesn't seem to be executing request

angularjs,karma-runner,karma-jasmine
I have an AngularJS app that is having some issues in testing. Method PlanService.prototype.getPlanList = function() { this.activeRequest = true; return this.PlanFactory.planList().then((function(_this) { return function(response) { _this.plans = response.plans; return _this.activeRequest = false; }; })(this)); }; return PlanService; Unit test: var planService; beforeach(function() { module("notRealModuleName"); inject(function(PlanService) { planService = PlanService;...

How to increase the coverage on testing angular directive?

angularjs,code-coverage,karma-runner,istanbul
So here is my angular directive. Simple one that uses a template url angular.module('my.directives') .directive('userNameDisplay', function() { return { restrict: 'E', scope: { user: '=user', status: '=status' }, templateUrl: '/partials/userNameDisplay.html' }; }); The spec is as follows. Again it tries to cover all cases. describe('user-name-display', function () { var elm,...

Executed 0 of 0 ERROR when running Karma on Cordova project

cordova,requirejs,karma-runner
I have an apache cordova project setup and I'm trying to use Karma for the first time. I've started the project like this: karma start test/karma.conf.js --verbose But all I'm getting is: INFO [karma]: Karma v0.12.36 server started at http://localhost:9876/ INFO [launcher]: Starting browser Chrome WARN [web-server]: 404: /favicon.ico INFO...

Managing dependencies in Angular JS karma grunt testing

javascript,angularjs,unit-testing,gruntjs,karma-runner
My controller : /** * @description * Controller for Comparative Analysis dashboard. */ (function (define) { define([], function () { /** * Constructor function. * * @param {Object} $scope Object that binds model to view. * @param {Object} $log object(angular service) to log info,waring and error messages. * */ //var...

Unknown provider: $routeParamsProvider

javascript,angularjs,karma-runner
I'm going through the AngularJS PhoneCat tutorial and while the application seems to behave correctly when I click through it manually, one of the unit tests are failing for step 8. Using Karma, I'm getting the following console output: Chrome 42.0.2311 (Windows 7) PhoneCat controllers PhoneDetailCtrl should fetch phone detail...

Angular/Karma TypeError: Cannot Read Property 'offsetTop' of Undefined

javascript,angularjs,jasmine,karma-runner,karma-jasmine
I wrote an angular directive to manipulate the DOM on scroll and now I am trying to write a test in Karma/Jasmine but I am having trouble getting even a simple test to pass, but I haven't been able to find a solution I could apply to my situation. this...

Error installing Karma with NodeJS

node.js,karma-runner
I try install Karma with command line: npm install karma and always receive the same error: npm ERR! Error: No compatible version found: [email protected]'^1.1.0' npm ERR! Valid install targets: npm ERR! ["0.1.0","0.1.1","0.2.0","1.0.0","1.1.0"] npm ERR! at installTargetsError (C:\Program Files\nodejs\node_modules\npm\lib\cache.js:709:10) npm ERR! at C:\Program Files\nodejs\node_modules\npm\lib\cache.js:631:10 npm ERR! at saved (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-registry-client\lib\get.js:138:7) npm...

Karma tests reporting fast runs, but actually running slow

javascript,angularjs,mocha,karma-runner,webpack
This is best explained with a video (or see the gif below): You'll notice that the Karma progress reporter is reporting that the tests are taking milliseconds, but it's obviously taking quite a while... I tweeted about this and was told to Try opening the debug page, and open the...

Karma: angular is not defined

angularjs,karma-runner
I've downloaded angular through bower and have included it in files in the conf file. File Structure/Files. When I run karma, the tests say: angular is not defined. I thought including it in the Files section was supposed to resolve it as a dependency. Any thoughts?...

I get an error — Error: [$injector:nomod] http://errors.angularjs.org/1.3.15/$injector/nomod?p0=decisionTree when I run karma.cong.js in Webstorm

karma-runner,webstorm
Here is my karma.conf.js file module.exports = function(config) { var configuration = { basePath : '', autoWatch : false, frameworks: ['jasmine'], files: [ 'bower_components/angular/angular.min.js', 'bower_components/angular-mocks/angular-mocks.js', 'bower_components/angular-resource/angular-resource.min.js', 'bower_components/angular-animate/angular-animate.min.js', 'bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js', 'bower_components/angular-cookies/angular-cookies.min.js',...

Running Karma and Protractor tests with or without a headless browser

selenium,teamcity,protractor,karma-runner,headless-browser
I am confused about running Karma and Protractor on a TeamCity CI server. Should I run these tests with a headless browser or not and how can I do that?

Trouble running a scope function in angular test

angularjs,unit-testing,mocha,karma-runner
I have recently started trying to learn how to test angular. I have had some success but at the moment I am trying to test a directive and I cannot seem to make it work. Test code describe('navigation test', function(){ var element, location, route, rootScope, scope, httpBackend; var elm; beforeEach(module('myApp'));...

Can not installing “Karma-Cli” in Windows 8.1?

node.js,karma-runner
I can't install Karma-cli in Windows 8.1. Afer running setup procedure in my terminal: npm install -g karma-cli I have some errors: npm WARN engine [email protected]: wanted: {"node":"~0.8 || ~0.10"} (current: {"node":"0.12.0","npm":"2.5.1"}) C:\Users\Marcona\AppData\Roaming\npm\karma -> C:\Users\Marcona\AppData\Roaming\npm\node_modules\karma-cli\bin\karma [email protected] C:\Users\Marcona\AppData\Roaming\npm\node_modules\karma-cli └── [email protected] How I can fix this errors? P.S. If I right understand,...

Karma: Executed 0 of 0 Error

requirejs,karma-runner
I think I have everything set up properly. I followed the specs of the Karma Tutorial for RequireJS, but everything I've tried seems to result in the same error. It appears that my test-main.js file is being loaded since a console.log() will fire. However, in the Object.keys loop, the files...

Setup karma to test a node.js module?

javascript,node.js,karma-runner
I'm developing a Node.js module, and I want to use Karma to auto-test it while working. In my config file, I setup this: // list of files / patterns to load in the browser files: [ './index.js', './test/indexSpecs.js' ], Obviously, since Node.js isn't included in the browser files, I get...

Writing the most basic Unit test in Angular 2?

javascript,unit-testing,karma-runner,ecmascript-6,angular2
Problem: As soon as I import Angular 2 into a file none of my tests execute. Question: How can I set up my karma config to support angular two so my test pass properly? OR Question: How can I set up any testing framework with angular2 written in es6? Git...

Karma - Load Files From Directories First

javascript,testing,karma-runner
My karma files config: files: [ ... app/scripts/**/*.js ... ], I have 4 directories under scripts directory, and app.js. I need the app.js to be loaded last (since it depends on other scripts). Any way to ensure this?...