Questions tagged [karma-jasmine]

Karma-Jasmine is an adapter for the Jasmine testing framework, which is shipped with Karma by default.

Karma-Jasmine is an adapter for the Jasmine testing framework.

Installation

This plugin ships with Karma by default, and there isn't any need to install it.

The easiest way is to keep karma-jasmine as a devDependency in your package.json file.

{
  "devDependencies": {
    "karma": "~0.10",
    "karma-jasmine": "~0.1"
  }
}

You can simply do it by:

npm install karma-jasmine --save-dev

Configuration

// karma.conf.js
module.exports = function(config) {
  config.set({
    frameworks: ['jasmine'],

    files: [
      '*.js'
    ]
  });
};
6563 questions
202
votes
21 answers

CUSTOM_ELEMENTS_SCHEMA added to NgModule.schemas still showing Error

I just upgraded from Angular 2 rc4 to rc6 and having troubles doing so. I see the following error on my console: Unhandled Promise rejection: Template parse errors: 'cl-header' is not a known element: 1. If 'cl-header' is an Angular component,…
Raphael Hippe
  • 4,535
  • 4
  • 13
  • 17
168
votes
3 answers

"Error: No provider for router" while writing Karma-Jasmine unit test cases

We have done one angular2 project set up and inside that created one module (my-module) and inside that module created one component (my-new-component) using following cmd commands: ng new angular2test cd angular2test ng g module my-module ng…
168
votes
14 answers

Expect Arrays to be equal ignoring order

With Jasmine is there a way to test if 2 arrays contain the same elements, but are not necessarily in the same order? ie array1 = [1,2,3]; array2 = [3,2,1]; expect(array1).toEqualIgnoreOrder(array2);//should be true
David says Reinstate Monica
  • 19,209
  • 22
  • 79
  • 122
163
votes
7 answers

Angular 2 Karma Test 'component-name' is not a known element

In the AppComponent, I'm using the nav component in the HTML code. The UI looks fine. No errors when doing ng serve. and no errors in console when I look at the app. But when I ran Karma for my project, there is an error: Failed: Template parse…
Angela P
  • 1,939
  • 2
  • 14
  • 18
154
votes
11 answers

Angular tests failing with Failed to execute 'send' on 'XMLHttpRequest'

I am trying to test my angular 4.1.0 component - export class CellComponent implements OnInit { lines: Observable>; @Input() dep: string; @Input() embedded: boolean; @Input() dashboard: boolean; constructor( public…
George Edwards
  • 8,979
  • 20
  • 78
  • 161
129
votes
8 answers

Firebase App named '[DEFAULT]' already exists (app/duplicate-app)

Hi I am trying to unit test while developing a simple web with AngularJS + Firebase, but I have a problem defining the spec and trying the test runner myProject/test/spec/main.js : describe('Controller: MainCtrl', function() { var MainCtrl,…
parkwookyun
  • 1,396
  • 2
  • 8
  • 9
127
votes
9 answers

Angular Karma Jasmine Error: Illegal state: Could not load the summary for directive

I'm developing a github repository (with angular 7 and angular-cli), and I have some tests with Karma and Jasmine working in the master branch. Now I'm trying to add lazy loading feature, the thing is, that the tests that before passed, now they do…
ismaestro
  • 7,561
  • 8
  • 37
  • 50
119
votes
8 answers

Found the synthetic property @enterAnimation. Please include either "BrowserAnimationsModule" or "NoopAnimationsModule" in your application. Angular4

When running Karma to test my Angular4 application, I get this error Found the synthetic property @enterAnimation. Please include either "BrowserAnimationsModule" or "NoopAnimationsModule" in your application. though I already imported the module…
Melchia
  • 22,578
  • 22
  • 103
  • 117
117
votes
17 answers

How do I debug a "[object ErrorEvent] thrown" error in my Karma/Jasmine tests?

I have several failing tests that only output [object ErrorEvent] thrown. I don't see anything in the console that helps me pinpoint the offending code. Is there something I need to do to track these down? [EDIT]: I'm running Karma v1.70, Jasmine…
Darrell Brogdon
  • 6,843
  • 9
  • 47
  • 62
109
votes
4 answers

Karma: Running a single test file from 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…
Gonçalo Vieira
  • 2,249
  • 2
  • 19
  • 39
100
votes
29 answers

Error: You need to include some adapter that implements __karma__.start method

I'm trying to add some unit tests to one of my projects. So far I've installed and configured karma, and have installed jasmine. I've one test file in my test/ folder. The karma server has started, the browser page is ready, but karma run fails as…
Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
98
votes
6 answers

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

When I run the command grunt I get the following warning: Running "karma:unit" (karma) task Warning: No provider for "framework:jasmine"! (Resolving: framework:jasmine) Use --force to continue. Does anybody know how to resolve this issue?
Thalatta
  • 4,510
  • 10
  • 48
  • 79
96
votes
2 answers

Angular 2 Testing - Async 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], …
xiotee
  • 1,519
  • 2
  • 14
  • 23
94
votes
6 answers

Angular unit testing with Jasmine: how to remove or modify spyOn

AngularJS v1.2.26 Jasmine v2.2.0 How can I change or remove the behavior of a spyOn? When I try to override it, I get the following error: Error: getUpdate has already been spied upon var data1 = 'foo'; var data2 = 'bar'; describe("a spec with a…
emersonthis
  • 32,822
  • 59
  • 210
  • 375
83
votes
5 answers

Angular/Karma unit test error "1 timer(s) still in the queue"

This is hardly first encounter I've had with "1 timer(s) still in the queue", but usually I find some way to use tick() or detectChanges(), etc., to get out of it. The test below was working fine until I tried to test for a condition that I know…
kshetline
  • 12,547
  • 4
  • 37
  • 73
1
2 3
99 100