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

TypeError: userAgent.toLowerCase is not a function

While running Angular-unit test, using chrome browser, ended up with the error as TypeError: userAgent.toLowerCase is not a function at _isAndroid…
Bhupendra Kumar
  • 179
  • 3
  • 7
0
votes
1 answer

How to test NGXS and withLatestFrom inside component?

I have a component that has addTodo method and todos property, when addTodo is invoked I get all the todos from NGXS store and assign them to todos property export class AppComponent { @Select("todo.todos") todos$!: Observable; …
Sameer
  • 4,758
  • 3
  • 20
  • 41
0
votes
1 answer

Keycloak role based redirection causes unit test error in angular app

I have an angular app which should whether redirect to /route1 or to /route2 based on the user role. The thing is that keycloak must have a single route to redirect to after logging in (which in my case is route1) and this is how I have solved the…
0
votes
2 answers

Unexpected value DecoratorFactory imported by the module DynamicTestModule. Please add a @NgModule annotation

I'm writing unit tests for an Angular component. When I attempted to run it, I received the following error: "Error: Unexpected value 'DecoratorFactory' imported by the module 'DynamicTestModule'. Please add a @NgModule annotation." Is there…
0
votes
0 answers

Is HTML covered in Angular default testing?

I have recently started working with Angular testing, I made a component using Material Angular auto Complete and I have conditional rendering inside it. I am using Karma and Jasmine for unit testing. This is the following output. Chrome Headless…
Van Wilder
  • 444
  • 4
  • 14
0
votes
1 answer

Unit testing component throwing transform is not a function for a pipe

in my component class i have following get method: get getCSVForDownload() { return defer(() => { this.downloadingData = true; return this.csvRepoService.getCSV(this.csvId).pipe( map((items: ICSV[]) => { …
0
votes
0 answers

Angular: How to detect UI changes and viceversa in unit tests

I am writing unit tests for an angular application and I am not able to detect the UI changes when the form values change. Here is some sample code html file
Krishna Chaitanya
  • 2,533
  • 4
  • 40
  • 74
0
votes
1 answer

Angular Unit Test: Uncaught Error: Uncaught (in promise): Error: Cannot match any routes

I am struggling with Angular Unit test on running "ng test", I get the below error in terminal. ERROR: 'Unhandled Promise rejection:', 'Cannot match any routes. URL Segment: 'my-account'', '; Zone:', 'ProxyZone', '; Task:', 'Promise.then', ';…
0
votes
1 answer

Angular Excluding external javascript library from unit testing

I am unit testing my component which uses a external javascript library, I am importing and initializing the libary in my component.ts All my test cases work fine if I comment the line aksService = aksServiceFactory(); (code below) but it gives a…
0
votes
1 answer

Jest toHaveBeenCalled is not able to watch the called method

I am writing unit tests for an Angular application. The method I am trying to test is as follows: onUrlEntry() { const fileUrl = this.componentForm.get('fileUrl'); if(fileUrl?.value) { this.URLService …
user18631150
0
votes
1 answer

error TS2552: Cannot find name 'xdescribe'. Did you mean 'describe'?

I am working on unit testing in angular application. And I have skipped some test suites by using xdescrie. Unfortunately, it is showing errors like error TS2552: Cannot find name 'xdescribe'. Did you mean 'describe'? when running the test by using…
0
votes
0 answers

How to write unit tests for presentational form component which gets it's form from the service in Angular?

I have a presentational form component which gets it's form from the service. Handling value changes, adding new controls, removing controls, etc happens in the service. I already wrote many test cases for the service but my company demands to have…
0
votes
1 answer

How to solve error "Can't bind to 'ngIf' since it isn't a known property of 'span'"

I am developing unit tests in an Angular 12 app with the help of Jest testing framework. Now there is a console error "Can't bind to 'ngIf' since it isn't a known property of 'span'" within child component after test run. By the way, the data which…
0
votes
1 answer

How write unit test cases for service file with rxjs next method

I am new to angular unit testing and I have tried to write test cases for service file. I need to write test cases for below code import { Injectable } from '@angular/core'; import { BehaviorSubject } from 'rxjs'; @Injectable({ providedIn:…
Sneha
  • 81
  • 1
  • 5
0
votes
1 answer

Unit testing with Angular 12 - Unable to function call inside ngFor loop

I am new in unit testing and now I am not able to call function which inside *ngFor loop of an angular 12 app. There is a observable that contains an array of objects and it works fine. Whole data is iterated properly. This is my HTML code.