273 questions
1 vote
1 answer
55 views
Angular unit testing - using debugElement.queryAll to get instances of a button
Running this unit test in Angular 21 always fails with the following error: × should toggle showSettings when settings button is clicked (440231 ms) ● DrawerComponent › should launch settings ...
0 votes
1 answer
55 views
Angular unit testing relative RouterLinks
In my Angular app I need to be able to unit test that routerLink create the correct href attribute. Sometimes they are links relative to the current route, and sometimes they are absolute links from ...
3 votes
1 answer
1k views
How to unit-test an Angular v19 `resource` and trigger the evaluation of input-signal changes?
I have a Service which contains a resource (for a list of country-objects). Unit-testing the usual way seems not to work, even with fakeAsync and tick. Changes on the Subject which feeds the request-...
0 votes
0 answers
35 views
How to unit test multple HTTP requests in Angular?
I have a simple Angular 19 component that will make multiple requests for SVG files, and then insert them into a component @Component({ selector: 'app-custom-svg-images', imports: [AsyncPipe], ...
-1 votes
1 answer
750 views
How use esbuild instead of webpack for unit tests
I have an application, which was generated with Angular CLI v19 and uses the application builder. The application builds and works perfectly fine, however when running ng test, I get a new error: ...
1 vote
0 answers
75 views
Unit test case failed using jest in angular
I am trying to create unit test case for the below code, export class TestService { currentContent$ = this.getContent().pipe( distinctUntilChanged((p, c) => isEqual(p, c)) ); ...
0 votes
1 answer
407 views
angular unit testing: element.animate is not a function
I am trying to test mat snackbar. I have following code in my component.ts snackbarRef: MatSnackBarRef<TextOnlySnackBar>; constructor(private snackBar: MatSnackBar) {} onUpdate(){ this....
2 votes
1 answer
1k views
After updating to Angular 19, some unit tests fail with NullInjectorError: No provider for ChangeDetectorRef
After updating my Angular project (including Angular Material) to v19, I am getting new errors like the following in my unit tests: NullInjectorError: R3InjectorError(Standalone[MyComponent])[...
8 votes
2 answers
2k views
Setup global providers for Angular unit tests
I have generated a fresh Angular 18 project and made it zoneless. It works fine, however in all of my unit tests I am now getting the following error: Error: NG0908: In this configuration Angular ...
1 vote
1 answer
292 views
TranslatePipe in test with Jest
I'm facing this error when I try to run test in an Angular project: NavigationMainComponent › should create TypeError: Cannot read properties of undefined (reading 'subscribe') at ...
3 votes
1 answer
1k views
How to add unit tests for Signal Queries?
I am using Angular's signal queries (viewChild, viewChildren, contentChild, contentChildren) like the following: export class MyComponent { myScrollContainer = viewChild('scrollContainer', { read: ...
2 votes
0 answers
217 views
Unit test effect in Angular
I am using Angular signal and to execute change in signal using effect function. How to mock signal to trigger effect during unit test. import { effect, Injector, Signal } from '@angular/core'; ...
0 votes
0 answers
120 views
Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) at <Jasmine>
I am getting following error when ran the unit tests in pipeline for an Angular app. Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) ...
3 votes
1 answer
10k views
Angular 18 - No provider for Http Client used on service for component Unit test
I have an application using Angular 18, and I have one component that uses a service. That service calls HttpClient, gets a list of entities and the component uses that on the constructor. The unit ...
1 vote
0 answers
2k views
Angular unit tests are failing with Error: NG0205: Injector has already been destroyed. in http://localhost:9876/_karma_webpack_/vendor.js (line 59623
We upgraded our Angular application from version 16 to 18. After the upgrade, our unit tests started failing with the following error: Error: NG0205: Injector has already been destroyed. in http://...