Questions tagged [angular-test]

Questions about testing Angular code, addressing either specific issues ("why is this test failing"), test flows ("how to test this async call of my component") or test setup ("how do I mock router in this component test"), integration tests ("how to bypass a proxy to my backend in this angular test"), or possibly test-related questions, such as ("Why does this component work and the test is failing?").

Angular test suite, running on top of Jasmine testing framework and Angular test framework.

Questions with angular-test tag about testing Angular code should address test code.

It can be related to specific issues ("why is this test failing"), test flows ("how to test this async call of my component") or test setup ("how do I mock router in this component test"), integration tests ("how to bypass a proxy to my backend in this angular test"), or possibly test-code-related questions, such as ("Why does this component work and the test is failing?").

This tag should not be used for generic and overbroad questions such as "How to test an Angular directive?" or questions that have no relation to Angular test suite ("I am testing my code in browsers, why does it not work?"), but rather test code itself. Rule of thumb can be, "does this question include parts of my *.spec.ts file.

A good angular-test question will, as any good test, include your expected results, your actual results, and your attempts so far, if possible with test code included.

More information on Angular Testing can be found on Angular guide on testing.

718 questions
2
votes
1 answer

How to run unit test case for toast message in angular service?

I am working with an app based on Angular 12. I have service called notification service which handles toast messages from ngx-toastr library. This is how that service looks like: export class NotificationService { constructor(private toastr:…
2
votes
1 answer

Jasmine test for checkbox change handler function in angular 12

I am trying to write simple test function for check box change, but I am unabled to run it. The error is Spec has no expectations. and the handler function is not covered in code coverage,. template:
LoneWolf
  • 119
  • 1
  • 11
2
votes
0 answers

Emit the event "onValueChanged" of a "dxi-item"

I'm trying to test if the method "changeValueCodeCompteurCET" is called when the "onValueChanged" event is emited. I tried a lot of times, but without any success (The code is bellow). Can u help find the problem in my code. Thank you for your…
2
votes
2 answers

Jasmine marble testing observable with ngIf async pipe

I want to test an Observable with jasmine-marble testing, but unfortunately I can't figure out how to trigger change detection for ngIf, which should render the component. This is a simplified version of my class: export class MyComponent implements…
JB17
  • 366
  • 5
  • 14
2
votes
0 answers

Angular 11 can't achieve to test if an url was called

I had a problem with angular testing. I want to detect when an url change on a button click. I followed a lot of similar issues on stack but can't achieve to my goal since 1 one week :/ Explanation Here is my HTML template:
iStornZ
  • 603
  • 1
  • 8
  • 19
2
votes
0 answers

how to mock fetch api call using angular jasmine

I have service where javascript fetch is used to call an endpoints How to mock fetch API calls in angular using jasmine fetch('https://' + this.sericeOption.url + '/rest/ms/2/user', { method: 'PUT', headers: headers, body:…
suchi
  • 83
  • 10
2
votes
2 answers

Angular Integration Testing - jasmine Spy - Can't mock a service method returning Observable

I am new to doing integration testing. And the whole thing is so confusing. For my first test, Seems like my spying is not returning the data as i intend to return it. Gives and error: Expected 0 to be 3. Will be great if someone could help me…
RBz
  • 896
  • 3
  • 17
  • 34
2
votes
1 answer

NgRX provideMockStore createSelector state undefined

When using the provide mockStore, my feature/selector functions only see state as undefined. Due to this, I am only able to mock the selectors and cannot therefore perform a more fully integrated test. Are selectors not supposed to see state when…
JoshuaTree
  • 1,211
  • 14
  • 19
2
votes
1 answer

Why I'm getting this error : NullInjectorError: R3InjectorError(DynamicTestModule)[MedicoService?

I'm taking a course about angular testing and I trying to setup a test for a componet with a service and this service has the httpClias as depedency but I got this error when I tried to run it NullInjectorError:…
geraktOfRivia
  • 325
  • 3
  • 7
  • 19
2
votes
2 answers

Set form control to dirty in angular test

I have the following component template:
{{model.title}} Some Error
2
votes
1 answer

Unit testing - onGridReady - Ag-grid event in Angular

I am having a function like below in my component file like below onGridReady(params) { this.gridApi = params.api; this.columnApi = params.columnApi; this.gridApi.setDomLayout('autoHeight'); this.gridApi.sizeColumnsToFit(); …
2
votes
1 answer

How to solve the InvalidPipeArgument 'AsyncPipe' error in Angular unit testing?

I get an InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe' error on the unit test when I use the | async pipe in the template. Tried to solve this with tick, fakeAsync and whenStable but that did not work. When I remove the | async part in…
Can
  • 553
  • 1
  • 9
  • 29
2
votes
1 answer

Angular: Testing Http POST method

I have a simple service method that does an http post call to add a todoList: add(event: any): Observable { let todoListToAdd: TodoList = { name: event.target.value, listItems: []}; return…
xeraphim
  • 4,375
  • 9
  • 54
  • 102
2
votes
2 answers

Angular Testing error - this._formBuilder.group is not a function

I have a standard function to register users. In the test file, I am getting the error: TypeError: this._formBuilder.group is not a function This seems to be from the ngOnInit function. I have tried importing the testing module numerous ways - as…
Joshua Foxworth
  • 1,236
  • 1
  • 22
  • 50
2
votes
2 answers

Angular testing with interval()

In my ngOnInit I check a route, do some stuff, and then setup an interval ngOnInit(): void { this.routeSubscription = this.route.paramMap.subscribe(x => { ... // Reload the data every 60 seconds interval(60_000) …
Gargoyle
  • 9,590
  • 16
  • 80
  • 145