Questions tagged testing

Explore the latest questions and answers asked by our top developers.

Angular Unit Test coverage getting success one time and failing another time

I was doing a unit test coverage for the angular app to increase the coverage percentage in Sonar QUbe. I’ve written around 200 test cases for the app. When I run ‘ng test –single-run –cc’. It is getting success for all test cases one time and some test cases are failing with the error ‘Uncaught […]

How do I do an Angular unit testing karma jasmine of this string function?

Angular unit testing karma jasmine of this string function, layouts come from the backend (layout.ts) – it should return a string like (1-"ABC"-(active)) getSelectedLayout(): string { const p = new ActivePipe(); if(this.layoutId === ”){ this.layoutId = this.layouts.find((x)=>x.status ===true)?.gridId.toString() as string; } const selectedLayout = this.layouts.find((x)=>x.gridId.toString() === this.layoutId); return( selectedLayout?.gridId + ‘-‘ + selectedLayout?.name + ‘(‘ […]

How to test conditional statements with Router correctly Angular

I am a newbie in Angular and need to test a method with conditional statements and routing. This is my method: onSubmit() { if (this.selection.length < 3) { this.notificationService.openFailureMessage(‘Choose three presentations.’); } else { var student = new Student(); student.id = parseInt(this.studentId, 10); student.presentationIds = this.selection; this.studentService.selectThreePresentations(student).subscribe(o => { this.notificationService.openSuccessMessage(‘Saved successfully.’); this.router.navigate([‘/’, ‘administration’, ‘students’, ‘edit’, […]

By ana
Published
Categorized as angular, testing, typescript Tagged , ,

Cannot read property ‘ ‘ of undefined – Angular Jasmine testing

I’m getting the following error: When trying to handle my "search-field" component error. The error is reported right at the start of my ngOnInit, and it’s not exclusively in the "iconFontSet" property and I don’t know what to do to fix it. The error that appears is "Cannot read property ‘iconFontSet’ of undefined", but when […]

By souzatorquato
Published
Categorized as angular, jasmine, testing Tagged , ,

DOM ElemRef does not behave as expected while testing component

I want to validate a login form. First, I have the login component which has a child component, a form created using stenciljs. This form has its own method called isValid(). This method will tell you if a form is valid or not. I have assigned the form a template and I have used the […]

By Juan Ortega
Published
Categorized as angular, elementref, testing, typescript Tagged , , ,

TESTBED.inject Cannot read property ‘getComponentFromError’ of null

I want to test an angular service that injects a script into angular components or page document this is my service: import { Injectable, Inject } from ‘@angular/core’; import { DOCUMENT } from ‘@angular/common’; @Injectable() export class NgxToolsLoadService { constructor(@Inject(DOCUMENT) private document: any) {} load( src: string, ): void { let el = this.document.createElement(‘script’); el.src=sec; […]

testing an angular service that injects a script into document

I want to test an angular service that injects a script into angular components or page document this is my service: import { Injectable, Inject } from ‘@angular/core’; import { DOCUMENT } from ‘@angular/common’; @Injectable() export class NgxToolsLoadService { constructor(@Inject(DOCUMENT) private document: any) {} load( src: string, ): void { let el = this.document.createElement(‘script’); el.src=sec; […]

By Sh eldeeb
Published
Categorized as angular, jestjs, testing, unit-testing Tagged , , ,

In the context of a common Spring and Angular application, what is the API?

There is a vast amount of information available on API’s. Guru99 has a good page on it. The information available is pretty general though. I am not sure exactly how it applies to the work I am familiar with. My work being that I commonly develop web applications with Spring and Angular. In this context […]

By Jack J
Published
Categorized as angular, java, spring, testing, web-api-testing Tagged , , , ,

Unit testing angular mat-form

I am new at Angular Testing. I want to test all the scenarios with a form (valid form, required form, etc) That’s my html: <div class="content" *ngIf="!recordsFound"> <div class="alert"> <span>OOOPS! No recordings found. You can add a new one:</span> </div> <form [formGroup]="recordingForm" #formDirective="ngForm" id="recordingForm"> <div> <div> <mat-form-field> <mat-label>Artist*</mat-label> <input matInput placeholder="Artist" formControlName="artist" /> <mat-error>Required input</mat-error> […]

How test event html in jasmine angular

I have some functions here in my project, but I decided to choose this one as an example. My function I want to test is this. <mat-select *ngIf="name != ” && formControl == undefined" [placeholder]="placeholder" [formControlName]="name" [multiple]="multiple" (selectionChange)="selectionChange($event)" > selectionChange = (event) => { let emit: any[] = []; if (this.multiple) { emit = this.selectOptions.filter((item) […]

By souzatorquato
Published
Categorized as angular, jasmine, testing Tagged , ,
1 2 3 21

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq