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.
4608 questions
87
votes
2 answers

How to test nodejs backend code with Karma (testacular)

How do I setup Karma to run my backend unit tests (written with Mocha)? If I add my backend test script to the files = [], it fails stating that require is undefined.
Sylvain
  • 19,099
  • 23
  • 96
  • 145
85
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
  • 56,083
  • 47
  • 179
  • 252
85
votes
8 answers

Loading a mock JSON file within Karma+AngularJS test

I have an AngularJS app set up with tests using Karma+Jasmine. I have a function I want to test that takes a large JSON object, converts it to a format that's more consumable by the rest of the app, and returns that converted object. That's it. For…
Aaronius
  • 4,936
  • 6
  • 31
  • 40
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
  • 22,016
  • 18
  • 111
  • 153
75
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,055
  • 1
  • 7
  • 11
75
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,876
  • 11
  • 48
  • 77
72
votes
16 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
  • 2,082
  • 2
  • 12
  • 8
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,593
  • 2
  • 17
  • 28
70
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
  • 3,972
  • 6
  • 26
  • 29
69
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
  • 2,283
  • 5
  • 28
  • 46
67
votes
14 answers

Testing Angular component with unsubscribe Error during cleanup of component

I'm testing a component which subscribe router params. Every test pass and everything works fine. But if I look in the console, I can see an error: Error during cleanup of component ApplicationViewComponent localConsole.(anonymous function) @…
BlackHoleGalaxy
  • 9,160
  • 17
  • 59
  • 103
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

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
  • 923
  • 1
  • 9
  • 15
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,668
  • 1
  • 28
  • 37
62
votes
10 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,671
  • 12
  • 46
  • 78