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
7
votes
3 answers

Angular ngrx store testing `The feature name "storeOne" does not exist in the state`

After I gone through the below video for ngrx isolated testing: John Crowson - Using MockStore in NgRx 8 | AngularUP I tried to implement the same with my simple project. But I am getting error which I am not able to understand. any one help me to…
user2024080
  • 1
  • 14
  • 56
  • 96
7
votes
1 answer

Angular testing HTTP Post calls

I have an angular component that will POST some data to a URL in our app, and then does nothing else since no data is returned back from that post. I am having trouble testing this since normally HTTP requests are tested by subscribing to the…
Chris Barr
  • 29,851
  • 23
  • 95
  • 135
7
votes
2 answers

Angular6 Test cases fail with unrelated error messge

I have migrated Angular 4 app to Angular 6 and now Test cases fail with following error message in terminal and it shows success on browser. Also, sometimes test cases pass without showing any error message. So we can say I get following error 60%…
7
votes
1 answer

Testing angular reactive form input value without setting formcontrol

I have a form like this:
I have a test like this: const inputUser: HTMLInputElement =…
7
votes
1 answer

Testing an HTTP request with retry() and HttpClientTestingModule

I want to test an HTTP call error response with the HttpClientTestingModule. This works fine until I add a rxjs retry(2) to the HTTP call. Then, the test obviously complains that an unexpected request is found: Expected no open requests, found…
Kim Kern
  • 54,283
  • 17
  • 197
  • 195
7
votes
4 answers

ng run test return error - TypeError: _this.handler.handle is not a function

I created the c3 bar-chart with angular 5.2.0. All are working fine. But I just want to run the test using karma and jasmine with npm run test. But I got the following issues. I hope it's related to rxjs function. But I can't understand the error…
7
votes
2 answers

Angular CLI - How to pick up .spec.ts files outside of the src folder?

I have an Angular CLI project with a NgModule located outside of the /src folder (eventually this NgModule will be packaged as a npm module but for now I'm just leaving it outside of /src). I'm trying to write unit tests for this NgModule but ng…
AngularChef
  • 13,797
  • 8
  • 53
  • 69
7
votes
2 answers

angular Testbed overrideModule not working

When using the following configuration for a test fixture, I get complaints that the tag cannot be found. Substituting the MockSelectionToolComponent directly in AppModule works fine, so must be something else... // Add the imported module to the…
jenson-button-event
  • 18,101
  • 11
  • 89
  • 155
6
votes
1 answer

Angular Ngrx Test: Store.overrideSelector does not override

I do have the following beforeEach: beforeEach(() => { fixture = TestBed.createComponent(ApplyComponent); component = fixture.componentInstance; fixture.detectChanges(); store =…
thomi
  • 1,603
  • 1
  • 24
  • 31
6
votes
2 answers

How do I go about testing a Pipe which depends on DomSanitizer?

Angular version: 8.1.2 Testing tools: Karma and Jasmine, as pre-installed by ng new I am currently working on my first ever Angular project. As a part of this, I have created a pipe which calls DomSanitizer.bypassSecurityTrustResourceUrl. I do this…
6
votes
0 answers

How to test angular guards/resolvers without mocking ActivatedRouteSnapshot

I'm trying to test an Angular Resolver which accesses children routes param. My guard works fine but I cannot create an unit test easily because I cannot create an ActivatedRouteSnapshot with children routes (read only property). My…
Martin Choraine
  • 2,296
  • 3
  • 20
  • 37
6
votes
1 answer

Angular 7 Testing - Async function call + async..await

In an Angular 7 unit test, is there a way to avoid the double async( async(){} ) syntax when combining async support along with the async..await keywords? I'm new to angular but am an experienced programmer, and I'm having trouble landing on my…
Jason
  • 4,897
  • 2
  • 33
  • 40
6
votes
1 answer

No provider for $injector in Angular Testing

I've been trying to setup testing in our Hybrid AngularJS/NG6 App but wow is this difficult to do. I keep getting constant errors. The latest is the following: Error: StaticInjectorError(DynamicTestModule)[$injector]: …
Edgar Quintero
  • 4,223
  • 2
  • 34
  • 37
6
votes
1 answer

testability.whenStable() returns, testability.isStable() returns false

Note this is not specific to Protractor. The issue is with Angular 2's built-in Testability service which Protractor happens to use. Protractor invokes Testability.whenStable via a call to waitForAngular. I've hit some code where this fails. My…
Mud
  • 28,277
  • 11
  • 59
  • 92
6
votes
1 answer

How to test an error thrown from a subscribe

I am testing the call function below in angular 4. import { Component, OnInit } from '@angular/core'; import { AppService } from './app.service'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls:…
Rupam Roy
  • 113
  • 1
  • 8