Questions tagged [karma-runner]

Karma provides developers a testing environment where they don't have to set up many things, rather just write code and get instant feedback in order to improve productivity and creativity.

Basic functionality

For all browsers connected to Karma's web server, source code is executed directly against test code. Developers receive the results of the tests on the command line with the ability to see which tests passed or failed for each browser.

Notice that Karma is only a test-runner, meaning it does not do testing itself. It runs tests implemented in some other test framework (e.g. Jasmine, QUnit, or Mocha).

Features

  • It can launch and run the test through real browsers.
  • It monitors file update on disk, and can instantly re-run required test giving very quick feedback on changes.
4451 questions
84
votes
9 answers

Karma run single test

I use karma for run tests. I have many tests and run all tests is very slow process. I want to run only single test in order to spend less time, because all test runs about 10 minutes. Is it possible ? Thanks.
user3730696
80
votes
2 answers

Unit testing AngularJS factories that have dependencies

When unit testing an Angular factory (with Karma + Jasmine), how do I inject a stub dependency into the factory under test? Here's my factory: mod = angular.module('myFactoryMod', []); mod.factory('myFactory', [ '$log', 'oneOfMyOtherServices',…
Roy Truelove
  • 20,716
  • 17
  • 105
  • 152
74
votes
5 answers

View Karma Test Output in a Browser?

I'm new to Karma, but I'm wondering how to view its output in a browser (much like the way one interacts with Jasmine, when a runner.html file is present). I watched the introductory screencast and I understand how to view test outputs in a console…
blaster
  • 8,566
  • 10
  • 43
  • 73
71
votes
11 answers

Angular 1.6.0: "Possibly unhandled rejection" error

We have a pattern for resolving promises in our Angular app that has served us well up until Angular 1.6.0: resource.get().$promise .then(function (response) { // do something with the response }, function (error) { …
Groucho
  • 1,015
  • 1
  • 7
  • 11
71
votes
3 answers

Mocking AngularJS module dependencies in Jasmine unit tests

I'm attempting to unit test controller code inside a module that takes other modules as dependencies, but haven't been able to figure out how to mock them properly. I'm using the Jasmine Framework and running my tests with Karma (Testacular).…
fscof
  • 1,523
  • 2
  • 17
  • 27
69
votes
9 answers

karma command not found when karma already installed

I used node.js to install karma. My first try failed when running the following command on Terminal: npm install -g karma That failed so I decided to use: sudo npm install -g karma After entering my password it seemed to install correctly. I am…
iChido
  • 2,252
  • 6
  • 21
  • 27
66
votes
5 answers

Unit-testing directive controllers in Angular without making controller global

In Vojta Jina's excellent repository where he demonstrates testing of directives, he defines the directive controller outside of the module wrapper. See here: https://github.com/vojtajina/ng-directive-testing/blob/master/js/tabs.js Isn't that bad…
64
votes
10 answers

Issue running karma task from gulp

I am trying to run karma tests from gulp task and I am getting this error: Error: 1 at formatError (C:\Users\Tim\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:161:10) at Gulp.
Timur
  • 6,428
  • 1
  • 23
  • 35
63
votes
10 answers

Angular 2 unit testing - getting error Failed to load 'ng:///DynamicTestModule/module.ngfactory.js'

I have angular 2 webpack application, all webpack,karma configuration created as per angular.io webpack guide. I am not using aot. I am writing jasmine unit test spec to test my components. First I tried without async block, in that case , unit…
Amit Gaikwad
  • 913
  • 1
  • 8
  • 14
61
votes
5 answers

How can I run tests with a headless browser?

Using: ng test Angular CLI runs the tests by default in Chrome, which is great, but what if I need to run them in a console-only environment (headless browser)? Also it would be nice if I can specify if I want browser-less or not each time I run…
Francesco Borzi
  • 37,945
  • 31
  • 126
  • 195
61
votes
9 answers

Error: No provider for "framework:jasmine"! (Resolving: framework:jasmine)

I have run on my windows console: npm install -g yo grunt-cli bower npm install -g generator-angular yo angular Then I started my project with webstorm and did right click on the karma.conf.js file in the project explorer where I have the menu…
HelloWorld
  • 4,100
  • 11
  • 38
  • 64
57
votes
10 answers

Angular 6 Unit Tests: An error was thrown in afterAll\nReferenceError: Can't find variable: $ thrown

When running my unit tests, from time to time, even if they pass, at the end of all the tests running, I will get the following error. On my Jenkins CI build running PhantomJS: .PhantomJS 2.1.1 (Linux 0.0.0) ERROR { "message": "An error was…
Oisin
  • 1,562
  • 1
  • 9
  • 7
56
votes
4 answers

ReferenceError: module is not defined - Karma/Jasmine configuration with Angular/Laravel app

I have an existing Angular/Laravel app in which Laravel acts as an API to the angular frontend serving only JSON data. The page that loads the angular app, index.php, is currently served by Laravel. From there, Angular takes over. I'm have a very…
Raphael Rafatpanah
  • 15,663
  • 19
  • 73
  • 136
52
votes
8 answers

How to debug Karma tests in Visual Studio Code?

I want to debug Karma tests in VS Code but I did not find out how. Is there any way to do that or will I have to use another IDE (WebStorm)?
geo
  • 1,913
  • 5
  • 23
  • 43
52
votes
1 answer

What are the differences between karma reporters?

I am looking at karma's reporter configuration. There are some possible reporters: progress, dots, growl, coverage. I don't find any detailed information explaining each of the options. I tried progress and dots, they all print log to console, the…
Aaron Shen
  • 7,354
  • 8
  • 40
  • 76