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
2
votes
1 answer

Angular-Testing: Angular5 spyOn not working in child components

I have an angular app and its one child module is loading by lazy loading. I am using this code in app.routing.ts to load that module. { path: '', component: FullLayoutComponent, data: { title: 'Home' }, children: [ …
2
votes
1 answer

How to make test case for angular animations

I use karma to write angular2 test cases, but have no idea how to test animations. I tried to get and check the transform attributes of host element, but got 'none', neither the 'getCalculateStyle()' method can work. Any suggestions? Example code…
2
votes
1 answer

Angular6: How can I generate a default angular.json file from command line

I create a new module using angular 6, that will serve as a package to use in another project. Now, I'm trying to configure the karma and jasmine so I could create unit tests on it. The problem is that I found out that the project does not have any…
Ricardo Rocha
  • 14,612
  • 20
  • 74
  • 130
2
votes
1 answer

Angular jasmine unit test error with 'and' on a spy

Can anyone shed some light on this error I'm seeing in my Jasmine unit tests where I'm creating a spy on a mock service call and trying to return a value? This is an example of the spy: mockService = jasmine.createSpyObj('MyService',…
2
votes
1 answer

Unit Test Angular @Input set function not triggered

In my Component @Input('price') set setPrice(price) { this.price = price; this.modifyTotalAmount(); } test (component.spec.ts) it('should call function ', () => { spyOn(fixture.componentInstance, 'modifyTotalAmount'); …
Sachithra Wishwamal
  • 117
  • 1
  • 2
  • 10
2
votes
2 answers

Angular 4 (karma) Test input value to input filed

I'm trying to test event which value entering by keyboard. my problem is after set value to the input field, when I print it prints, but when I print it inside the whenStable() it prints empty. I want to know why this value gets reset inside of the…
Sachithra Wishwamal
  • 117
  • 1
  • 2
  • 10
2
votes
0 answers

NG Test errors with "cannot find module..."

So I've inherited an Angular 6 project that's fairly large. Everything runs fine via ng serve, however when I try and run ng test I receive a litany of errors indicating that it cannot find a module. src/app/shared/services/view-as.service.ts(4,24):…
Trattles
  • 647
  • 1
  • 6
  • 21
2
votes
0 answers

HttpTestingController does not work with HTTP_INTERCEPTORS

What is needed to do in this test, it is expected the request successfully get to the backend (which is HttpTestingController in this case) and in between client and backend, the interceptors intercept the request. Interceptors check and set…
2
votes
1 answer

Basic create component test failing with MoJs

I have a component that is using the animation library Mojs. The create component test that comes out of the box with the spec.ts file is failing because of MoJs elements. I am not sure how to provide this library in the spec.ts file so that at the…
Brian Stanley
  • 2,078
  • 5
  • 24
  • 43
2
votes
1 answer

Angular Unit test with setTimeout

My component looks like this, where in the Init I get my initial data from a service and then I call the same function every 15 seconds to update that data: networkGraph: NetworkGraphComponent; hideSpinner: boolean = false; ngAfterViewInit() { …
iamcootis
  • 2,203
  • 3
  • 18
  • 22
2
votes
2 answers

Angular unit testing: How to serve css files now in karma with angular 6+

I wanna have material css in my specs. Before I had it like this in karma config: files: [ // make sure material styles are served { pattern: './node_modules/@angular/material/prebuilt-themes/indigo-pink.css', watched: true, included: true,…
fr00t
  • 681
  • 1
  • 4
  • 19
2
votes
1 answer

Jasmine / Karma error as cannot read property of undefined

I am trying to create cover all the line (Jasmine / Karma) but I am getting the error as Cannot read property 'search' of undefined Here is my code for component code. public search() { if (this.searchCompany.length) { let term =…
Mr.M
  • 1,472
  • 3
  • 29
  • 76
2
votes
1 answer

How to use spy from jasmine

I am very new to Angular and jasmine and I am facing issues while I am doing mock: public uploadFile(confirm) { this.uploadModalRef.close(); if (this.filePath.length) { let ngbModalOptions: NgbModalOptions = { backdrop : 'static', …
Mr.M
  • 1,472
  • 3
  • 29
  • 76
2
votes
2 answers

Karma complains about missing provider in component, but provider is not directly injected into component

I have an Angular application and when running unit tests with Karma, I get an error in saying that there is a missing provider for the Store in a component. The store is not directly injected into the component, but into a service that is injected…
MartaGalve
  • 1,056
  • 3
  • 13
  • 34
2
votes
2 answers

No provider for InjectionToken Custom HTTP Config

I am new to karma and jasmine, so please forgive me if this sounds silly. I have these following code and what I want to do with it, is finding out what I need to do next. I have CUSTOM_HTTP_CONFIG injected in the constructor in…
roger
  • 1,225
  • 2
  • 17
  • 33
1 2 3
99
100