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
2 answers

Subscription to an observable is undefined only when running Angular Jasmine test, but is defined when running the app itself

I have written a unit test for this function: getCarsAndSetup(){ this.getCars(); this.getFactoryInfo(); } This is the getCars() function: getCars() { const subscription = this.carDetailsService.getAll().subscribe((carDetails) => { …
GeForce RTX 4090
  • 3,091
  • 11
  • 32
  • 58
2
votes
1 answer

Karma tests using a Docker image of Chrome

For tests on CI server I want to use an image of Chrome instead of PhantomJS. I can do this with and without puppeteer but both require me to install chrome-stable package on the server. Thus I want a more lightweight method hence the use of the…
Nanotron
  • 554
  • 5
  • 16
2
votes
1 answer

How to fix 'cannot read property subscribe' of undefined during angular unit testing?

Angular6 - Unit testing error “Cannot read property 'subscribe' of undefined” I was writing a unit test for an angular component which is having several dependencies. One of those dependent service has some properties as observables. I tried to mock…
Arun Mohan
  • 21
  • 2
2
votes
1 answer

Angular Jasmine testing - onLangChange callback not executed

I've just started writing unit tests for my Angular project, and I'm experiencing some problems with testing if the language is set. This is the code of my app.component.ts: ngOnInit() { this.translateService.setDefaultLang('en'); …
GeForce RTX 4090
  • 3,091
  • 11
  • 32
  • 58
2
votes
3 answers

Retrieving css color attribute using using Protractor

I need to validate the color of a email link text . Below is my code: it('Contact Text Validation', function(){ expect (Contact_info_on_Login_screen.isDisplayed()) var Email_Link = element(by.css("body > app-root > app-login > div > div…
nhrcpt
  • 862
  • 3
  • 21
  • 51
2
votes
2 answers

Unit-testing with Jasmine/Karma on an Angular Google Charts component

I haven't found any way of doing an unit-test with Jasmine/Karma on an Angular2component which renders a chart from Google Charts. So I propose my own Q&A in the hope that it could help other people also testing it: What could be a good way to write…
2
votes
1 answer

How can make my Jasmine test reach this callback inside mergeMap?

I'm working with Angular6 and I'm trying to make my Jasmine test reach the callback inside mergeMap bellow, but after days of work I just can't do it. My test returns correctly the refresh method, but it just doesn't seem to follow through the…
Анна
  • 1,248
  • 15
  • 26
2
votes
1 answer

how to test angular service injected in another service

i am testing a service in angular(1.6.3) My service is dependent on another service. every time i run ng test i get no provider for ServiceName or HTTpclient any help???? service: export class TraitsService { constructor(private gs:…
k_hotspot
  • 134
  • 1
  • 1
  • 13
2
votes
2 answers

Error of 'appendchild' of null during running ng test in angular 6

I have an angular 6 project with typescript 2.8.0 and node version 11. I have a functional dev application and trying to setup a unit testing environment with jasmine karma, due to limited knowledge about these frameworks I am not able to debug the…
shitterpunk
  • 141
  • 1
  • 1
  • 8
2
votes
1 answer

Implement unit testing with jasmine/karma by mocking Http Post - Angular 5

I am completely new to unit testing and I am implementing unit testing using jasmine/karma for the first time. I am facing few issues in understanding how I should implement testing by mocking for Http Post. I have gone through few solutions such as…
user10648256
  • 113
  • 8
2
votes
0 answers

jasmine karma @viewChild to open the model shows this.$modal.modal is not a function in angular 5

I am new to jasmine karma test cases, when I called the openMail method from spec file it shows this.$modal.modal is not a function errors. can anyone help me to solve this issues MY spec file it('should call openMail ', () => { …
RamKumar
  • 126
  • 1
  • 10
2
votes
1 answer

How to mock Image object with Karma (Angular 7)?

I'm trying to mock the default DOM Image object for unit testing an Angular service. The service is simple, it checks the "webP" format support : import {Injectable} from '@angular/core'; import {Promise} from 'es6-promise'; import {environment}…
Doubidou
  • 1,573
  • 3
  • 18
  • 35
2
votes
1 answer

How to write Unit Test Case for below javascript function using Jasmine

How to write Unit Test Case for below javascript function using Jasmine? function GetURLParameter(sParam) { var sPageURL = window.location.search.substring(1); var sURLVariables = sPageURL.split('&'); for (var i = 0; i <…
Mandeep Rehal
  • 93
  • 2
  • 4
  • 11
2
votes
0 answers

Angularfire not passing karma Test

I implemented Jasmine/Karma inside of my angular webapplikation. When I do ng test I keep getting a error because of firebase. I get the error: "Cannot read property firestore of undefined" This is my error-> enter image description here This is my…
2
votes
1 answer

How to write Unit Test Case for javascript function with "document.write" in it

I have a JavaScript function with "document.write" in it, as below: function sampleFunction(){ document.write('hello world'); } And, for this wrote a unit test case in Jasmine, as below: describe("testing function", function() { …
1 2 3
99
100