Questions tagged [angular-unit-test]

Questions about Angular unit testing. Use this tag for Angular unit testing questions which are not specific to an individual version. Do not use this tag for the older AngularJS (1.x) web framework uni testing questions.

Angular unit testing is based on two systems. Jasmine (The testing framework) and Karma (The test runner).

The Angular CLI takes care of Jasmine and karma configuration for you.

You can fine-tune many options by editing the karma.conf.js and the test.ts files in the src/ folder.

The projects that you create with the CLI are immediately ready to test. Just run ng test CLI command to run the tests.

Useful Links

256 questions
0
votes
1 answer

Unit test Keypress event directive in angular

I have a directive that prevents users from entering the alphabets. for unit testing I planned to execute that I will trigger a keypress event and if its number it will be there in the text box if not it should not. when I run the test, the event…
0
votes
1 answer

How to write the unit test case for angular material dialog

Question: How to perform unit test in angular on material dialog box. I tried many things but it seems to be not working. I am new to unit testing, please help Dialog-modal.component.ts import { Component, OnInit } from '@angular/core'; import {…
ksahu
  • 51
  • 1
  • 4
0
votes
1 answer

Jasmine Angular Unit testing with subscribe

------Service file ------- postStatus(status: String) { return this.http .post(url, null, { headers: new HttpHeaders({"Content-Type": "application/json"}), observe: "response" }) .subscribe( …
0
votes
1 answer

Headless Chrome Issue on Jenkins for Angular 6

I am running Angular 6 unit tests using Karma and below is my configuration : karma.conf.js : module.exports = function (config) { config.set({ basePath: '', frameworks: ['jasmine', '@angular-devkit/build-angular'], plugins: [ …
Atul
  • 1,560
  • 5
  • 30
  • 75
0
votes
1 answer

Jasmine spy on base class protected property

I have a scenario to spy the protected property from the base class. export class BaseClass { protected property1: string; } export class InheritedClass extends BaseClass, OnInit { ngOnInit() { this.populateProperties(); } …
Hary
  • 5,690
  • 7
  • 42
  • 79
0
votes
1 answer

How do I write test cases to cover the lines within subsribe callback function

In my component, I have this code: setTakenNcatsNames(): void { if (this.settings.route){ this.dataService.getAll(this.settings.route).subscribe(result => { console.log('in herer'); this.arrTakenNcatsNames =…
Van Le
  • 3
  • 2
0
votes
1 answer

How to fake child components while unit testting

I'm new to testing with Jasmine and Karma. Pardon me if I'm asking anything wrong. I've a component app-timeselector inside which there are some custom child components. The template looks…
Tanzeel
  • 4,174
  • 13
  • 57
  • 110
0
votes
0 answers

How to unit test a component with TranslateService

I followed this very carefully: Git issue #636. But I'm not able to solve my problem. Let me explain. I've a TimeSelector component for which I've externalized all strings in a file i18n/en-US.json. Initially when the page loads, I'm setting…
Tanzeel
  • 4,174
  • 13
  • 57
  • 110
0
votes
1 answer

How to fix this test case: Can't bind to 'value' since it isn't a known property of 'dls-option'

This is my day 3 in Angular unit testing with Jasmine and Karma. I'm following Pluralsight lectures. First thing first, dls-option is a component which I'm using form a library. I'll explain. I'm using a library of angular components provided by our…
Tanzeel
  • 4,174
  • 13
  • 57
  • 110
0
votes
1 answer

Angular: How to write a unit test for template variable

I'm working page auto scroll when click on the button and I'm using template variable as target point. How to write a unit testing for scrollToSecondPage function which has template var as param. app.component.html

section 1

SKL
  • 1,243
  • 4
  • 32
  • 53
0
votes
2 answers

Testing submitted data from Angular Reactive form

Based on the very first example in https://angular.io/guide/reactive-forms, I create the following dumb component: @Component({ selector: 'app-name-editor', templateUrl: './name-editor.component.html', styleUrls:…
0
votes
1 answer

How to unit test a service in angular unit testing?

I have a function in my service as follows,, exportPayGapDetails(filterObject: PayGapDetailFilter): void { const url = `${this.payGapDetailExportUrls[filterObject.type]}`; this.http .post( …
learner
  • 357
  • 1
  • 6
  • 16
0
votes
0 answers

Why Karma is not running specific component tests only?

I have an Angular app in which i have many components. But for now I just want to run the tests for login.component.ts so for that I did in my test.ts file like this const context = require.context('./', true, /login\.component\.spec\.ts$/); But…
ahsan
  • 277
  • 1
  • 5
  • 18
0
votes
1 answer

How to test multilple subscription in Angular?

In my Angular Unit Test I want to check whether myComponent.items$ have 0 results when I call subject myComponent.clearInput$.next(). Before that I want to ensure that there are some records. myComponent.items$ can be populated by…
DiPix
  • 5,755
  • 15
  • 61
  • 108
0
votes
1 answer

How to get value Angular unit test CSSStyleDeclaration

I try test Angular material mat-expansion-panel open. So, I test with below code. describe('Selected first expansion panel', () => { beforeEach(() => { const header = fixture.debugElement.query(By.css('#panel1…
ATHeart
  • 65
  • 1
  • 8