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
0
votes
1 answer

why are the tests failing

Trying to test http get service here but the test fails. why is it not working. I have provided all the dependencies and everything but still it's giving the response as undefined and when I run the karma test runner the test fails to give the…
SONGSTER
  • 585
  • 3
  • 11
  • 28
0
votes
0 answers

angular test error TypeError: Attempted to assign to readonly property

When I try to assign a value to property of fixture.debugElement.nativeElementit gives me error. fixture.debugElement.nativeElement.clientWidth = 4501; I checked in the debugger and fixture.debugElement.nativeElement.clientWidth exist and its not…
Aniruddha Das
  • 20,520
  • 23
  • 96
  • 132
0
votes
1 answer

Calling function by triggering selectChange event Angular testing

I started working on a small project in Angular(v4.0.0). In this project, I am adding unit testing. I read the angular testing documentation and now have basic understanding of how to write unit testing in angular. In this, I am struggling writing…
yugantar kumar
  • 1,982
  • 1
  • 23
  • 33
0
votes
1 answer

angular mouse enter unit test is not working

I am trying to test a mouse enter in angular 4 karma unit testing, There are not errors but the mouse enter is not calling the method binded to the mouse enter event.
Aniruddha Das
  • 20,520
  • 23
  • 96
  • 132
-1
votes
1 answer

Angular testing error thrown on testing subscribe method under a function as ` Error: Expected spy updateClinics to have been called.`

My real method: postClinicUpdate() { this.postProfile(); if (!this.profileForm.isHfsFormIsValid) { return; } const { slide, timezone: { codeId }, } = this.profileFormValue; const { sjmAccDTO } =…
3gwebtrain
  • 14,640
  • 25
  • 121
  • 247
-1
votes
1 answer

How to make coverage with internal observable method in testing

here is the component methods: resetPage(): void { this.deletedClinicPosProps = { appId: [] }; this.addedClinicPosProps = { appId: [] }; this.resetHeaders(); this.canSaveEnabled = { a: false, b: false, c: false }; …
3gwebtrain
  • 14,640
  • 25
  • 121
  • 247
-1
votes
1 answer

Not able to set mock and with a subscription for testing

I am getting following errors while do the test: TypeError: Cannot read properties of undefined (reading 'subscribe') Error: : Expected a spy, but got Function. Not able to understand with these erros. Here is my spec…
3gwebtrain
  • 14,640
  • 25
  • 121
  • 247
-1
votes
1 answer

Angular spectator testing: target component-level service

In my Angular app I have a service which is provided at a component level: @Component({ selector: 'my-component', templateUrl: './my.component.html', providers: [MyService], }) export class MyComponent implements OnInit, OnDestroy { ... } I'm…
-1
votes
1 answer

sortableData break the testing

I have next snippet in my html ... receiving next error on unit testing Template parse errors: Can't bind to 'sortableData' since it isn't a known property of 'tbody'. (" …
IgorK
  • 148
  • 8
-1
votes
1 answer

angular 2+ test failing in pipeline but feature is working

I dont know anything about testing and the feature is working completely but failing in pipeline. Here is my spec.ts file code let component: CustomerDocumentUploaderComponent; beforeEach(()=>{ let clientFilter:ClientFilterService = {} as any; …
Ishan Malik
  • 19
  • 1
  • 7
-1
votes
1 answer

How do I configure IntelliJ Run/Debug to execute only the current *.spec.ts file for ng test?

I am attempting to execute the Angular Test against a single spec.ts file on my CentOS box. I can use the command line from the OS terminal or within IntelliJ Terminal *ng test --include="somefile.spec.ts"* and the Angular Karma Test will run just…
edjm
  • 4,830
  • 7
  • 36
  • 65
-1
votes
1 answer

Angular Cannot read properties of undefined (reading 'patchValue')

I have this component that I want to test but I keep getting the following error message TypeError: Cannot read properties of undefined (reading 'patchValue') The component: import { Component, EventEmitter, Input, OnInit, Output } from…
Andrew
  • 2,571
  • 2
  • 31
  • 56
-1
votes
1 answer

ngrx testing effects action failure

I've got this effect login$ = createEffect(() => this.actions$.pipe( ofType(AuthActions.login), exhaustMap((action) => this.service.login(action.credentials).pipe( map((data: LoginResponseDto) => { …
user3887366
  • 2,226
  • 4
  • 28
  • 41
-1
votes
1 answer

'router-outlet' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' when ever i write unit testing

As you can see I am testing the application using unit testing in angular7, when ever I am running ng test. I am getting issue like router-outlet is a Web Component then add CUSTOM_ELEMENTS_SCHEMA to the @NgModule.schemas of this component to…
-1
votes
1 answer

NodeJS docker image to run Angular test in gitlab-ci

I have a small Angular app which I am try to build using gitlab-ci and node docker image, when I try to run the test using the command npm run test it fails with the following error : ERROR [launcher]: No binary for Chrome browser on your platform.…
Sathish
  • 101
  • 7
1 2 3
47
48