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
44
votes
5 answers

TypeError: Cannot read properties of undefined (reading 'id')

I have this error in my terminal: TypeError: Cannot read properties of undefined (reading 'id') I'm trying to test the call to an API, but the error appears. My function: itemToForm = () => { this.api.send(this.component, 'get', {…
David Angarita
  • 740
  • 4
  • 8
  • 15
44
votes
6 answers

how can i run a specific angular spec test file in NX workspace?

is there any way to run an specific angular spec test file in Nx work space? Recently i moved my Angular 4 cli application into Nx work space. Previously i used fdescribe to achieve this functionality. So please suggest me if there is any…
Raj Kumar
  • 583
  • 2
  • 5
  • 9
44
votes
5 answers

Angular 4 - Failed: Can't resolve all parameters for ActivatedRoute: (?, ?, ?, ?, ?, ?, ?, ?)

I have referred the following link to get the answers, but I couldn't find any working solution for my scenario. Error: (SystemJS) Can't resolve all parameters for ActivatedRoute: (?, ?, ?, ?, ?, ?, ?, ?) Therefore, I have been trying to remove the…
Lakindu Gunasekara
  • 4,221
  • 4
  • 27
  • 41
44
votes
3 answers

Expect not toThrow function with arguments - Jasmine

I have function that gets 3 arguments. I want to check that this function not throwing an error. I did something like this: expect(myFunc).not.toThrow(); The problem is myFunc need to get arguments. How can I send the arguments? P.S I tried to pass…
Sagie
  • 996
  • 3
  • 12
  • 25
43
votes
5 answers

MatDialog Service Unit Test Angular 6 Error

I'm having modal service to open, confirm and close dialog and i am making its unit test file but i got and error on Angular and this is the code. modal.service.ts @Injectable() export class ModalService { constructor(private dialog: MatDialog) {…
rj.learn
  • 645
  • 1
  • 6
  • 14
42
votes
5 answers

TypeError: undefined is not a constructor

I'm very new to Angular and I'm trying to figure much of this out still. I'm writing some tests using Angular 1.5.8 which I generated from the Yeoman Generator. Specifically, I'm trying to figure out how to manipulate $httpBackend results (I'm not…
Adam Plocher
  • 13,994
  • 6
  • 46
  • 79
42
votes
4 answers

Testing ngOnChanges lifecycle hook in Angular 2

Given the following code I try to test the ngOnChanges lifecycle hook of Angular2: import { it, inject, fdescribe, beforeEachProviders, } from '@angular/core/testing'; import {TestComponentBuilder} from…
user1448982
  • 1,200
  • 3
  • 12
  • 22
42
votes
2 answers

How do I exclude files from karma code coverage report?

Is there a way to exclude files from code coverage report for the karma coverage runner https://github.com/karma-runner/karma-coverage ?
Subtubes
  • 15,851
  • 22
  • 70
  • 105
40
votes
16 answers

Karma - Chrome failed 2 times (cannot start). Giving up

I've been trying to run my tests using karma-chrome-launcher, but everytime I run my tests it throws this error: INFO [launcher]: Starting browser Chrome ERROR [launcher]: Cannot start Chrome INFO [launcher]: Trying to start Chrome again…
SupimpaAllTheWay
  • 1,308
  • 3
  • 16
  • 22
38
votes
5 answers

how to fix Error: ASSERTION ERROR: Should be run in update mode [Expected=> false == true <=Actual]

Im writing a code with in angular with ChangeDetectorRef The function itself is working fine. getVersionInfos() { concat( of( this.getApiSubs = this.aboutInfoService.getApiVersion().subscribe((data) => { if (data) { this.apiData…
nhoyti
  • 1,615
  • 2
  • 26
  • 42
38
votes
5 answers

How do I unit test if an element is visible when the *ngIf directive is used using Jasmine in Angular

I have an Angular 6 app and writing some unit tests trying to determine if an element is visible or not based solely on the boolean result of an *ngIf directive. Markup:
...
spec…
J-man
  • 1,743
  • 3
  • 26
  • 50
36
votes
3 answers

Angular testing how to prevent ngOnInit call to test a method directly

Context I have a component. Inside of it, the ngOnInit function calls another function of component to retrieve user List. I want to make two series of tets: First test the ngOnInit is triggered properly and populate the user list In a second time…
BlackHoleGalaxy
  • 9,160
  • 17
  • 59
  • 103
36
votes
2 answers

Updating the version of Jasmine used in karma-jasmine

Questions How can I update the version of Jasmine used when running Jasmine via Karma using the karma-jasmine plugin? Will Jasmine only get updated whenever the karma-jasmine plugin integrates a newer version of Jasmine, or can I point the…
Matthew Rankin
  • 457,139
  • 39
  • 126
  • 163
35
votes
3 answers

Angular - unit test for a subscribe function in a component

Angular 4 unit test for a subscribe. I want to test that my subscribe returns an array of Users. I want to mock a list of users and test a function called getUsers. The subscribe unit test doesnt work. Something wrong with the syntax. This is my…
AngularM
  • 15,982
  • 28
  • 94
  • 169
34
votes
2 answers

What is the difference between fakeAsync and async in Angular testing?

I know that tick() function utilizes fakeAsync(). And also I can use fixture.whenStable().then() with async() and fakeAsync() as well. I want to know the exact use case for both of them. Can anyone explain this with examples. Note : I want to use…
Amit Chigadani
  • 28,482
  • 13
  • 80
  • 98