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

Why angular unit test for child-class extending abstract base class with dependency injection not working?

child-class component(BusinessRegistration) export class BusinessRegistration extends BizAbstractRegistration { constructor(protected readonly injector: Injector) { super(injector); } other methods.... } base class abstract with DI export abstract…
0
votes
2 answers

Angular Testing 'Expected undefined to be truthy.'

This error comes up even with just the boiler plate for the spec file. Is there any other issues causing this? ts file import { Component, OnInit, Input, Output, EventEmitter, ViewContainerRef } from '@angular/core'; import { NzNotificationService }…
0
votes
0 answers

How to test a viewChild on Angular with Jest - Unit test?

I am having problems trying to test a viewChild on Angular with Jest. Here my .ts component: import { MurQueryViewComponent } from '../../shared/components/mur-query-view/mur-query-view.component'; @ViewChild(MurQueryViewComponent) private…
Jmainol
  • 357
  • 4
  • 18
0
votes
0 answers

Unable to mock FullCalendar's getApi() that returns a mock Calendar (Angular & Jasmine, Karma)

I'm trying to write test cases around a component that contains my FullCalendar component in Angular. I've written karma tests using a MockFullCalendar that extends FullCalendar and have been successfully able to mock the getApi().view calls for…
0
votes
2 answers

Cannot trigger click event undefined element

I need to test click event on mat-table row. Below is my mat-table code
0
votes
1 answer

How to write unittest for a class use socket.io-client

I have a class which use Socket as a private property. import {Socket} from 'socket.io-client'; export class SocketService { private socket: Socket; public initializeSocket() { if(this.socket) { return; } this.socket = // get a…
Kerwen
  • 516
  • 5
  • 22
0
votes
2 answers

How to test the method of a private property is called in Angular

I have a class which has a private property. import {Socket} from 'socket.io-client'; export class SocketService { private socket: Socket; public initializeSocket() { if(this.socket) { return; } this.socket = // get a new…
Kerwen
  • 516
  • 5
  • 22
0
votes
2 answers

Getting cannot read properties of undefined (reading:'viewMode') in Angular Unit Testing

Hi I have a function which I would like to unit test. This is my function. let docProcess: IDocProcess; public onCalling(args) { if (this.docProcess.viewMode) { this.makeCalls(args); } } This IDocProcess is an interface: export…
0
votes
0 answers

Getting error : : Cannot read properties of undefined (reading 'deps') while running angular test file

Please find the describe in test file : ` fdescribe('NdelDeviceBalancePayoffComponent', () => { let component: NdelDeviceBalancePayoffComponent; let fixture: ComponentFixture; let ndelUpgradeService:…
0
votes
0 answers

Module '"@angular/router/testing"' has no exported member 'SpyNgModuleFactoryLoader'

I am facing this error in angular unit testing.How can I import SpyNgModuleFactoryLoader in Jasmine-Karma angular unit testing?
0
votes
0 answers

graphql / Apollo test case for a service call fails with Error: Expected one matching operation for criteria "Match DocumentNode", found none

I am trying to write a test for an angular component service call which is using graphql & Apollo and I end up getting this Error.'Error: Expected one matching operation for criteria "Match DocumentNode", found none.'. I have also tried putting…
0
votes
1 answer

Angular unit testing check if input is undefined

I am unable to test else condition in my code as Unable to change value of input(). Please help. Once I pass data in spec.ts unable to assign other data @Input() data: any; ngOnInit(): void { if (this.data !== undefined) { this.fn1() …
0
votes
1 answer

After completion of ng test, getting Uncaught [object Object] at /_karma_webpack_/polyfills.js

Test cases are running successfully but at the end it gets returned with an Uncaught [object Object] error which looks like this: - Test script: ng test --codeCoverage=true --no-watch --no-progress --browsers=ChromeHeadless Angular: 8 package.json…
0
votes
1 answer

Observable test function call in pipe tap

I'm trying to cover this.httpCache.put(this.agreementUrl, agreement as any); line in test but it always fails, public getTransportAgreement(): Observable { const cache: TransportAgreement = this.httpCache.get( …
0
votes
1 answer

how to write Angular12 unit test with Private method and local variables

export interface UserDetails { name: 'string', id: 'string', address: { area: 'string', city: 'string', }} export class UserComponent { Private GetData() { let userDetail: UserDetails = { name: 'user name' } userDetail.address.city = 'city Name';…
Peri
  • 158
  • 1
  • 4
  • 16