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

Angular testing: tick vs flushMicrotasks in fakeAsync block

As far as my understanding goes from reading the Angular testing docs, calling tick() flushes both (supported) macro tasks, and micro-task queues within the fakeAsync block. In which case, under the hood, I assume, calling tick() will be the same as…
Glenn Mohammad
  • 3,871
  • 4
  • 36
  • 45
6
votes
2 answers

Unit test html element with ngif async call in angular 2 jasmine

I am writing unit test for html div having a *ngIf condition.
Nimish goel
  • 2,561
  • 6
  • 27
  • 42
6
votes
1 answer

Why does this Angular Validation Directive appear async?

I wanted to use template forms and [min] and [max] directives, so I have created them and they work. But the test confuses me: validation is not executed asynchronously, yet after changing my values and stuff, I have to go through…
Zlatko
  • 18,936
  • 14
  • 70
  • 123
6
votes
2 answers

Angular testing spyOn on private variable

How test the call on method of private variable ? I must test the call of unsubscribe method when the ngOnDestroy is called. There is my code import { Component, OnInit } from '@angular/core'; import { Subscription } from 'rxjs/Subscription'; import…
NICO
  • 71
  • 1
  • 4
6
votes
2 answers

Angular Cypress.io test with Google Login popup window

Is it possible to login to a Google account with Cypress.io using the Google authentication pop-up window? I can get the window to open, but then Cypress can't detect the ID for the email input field. The error is: "CypressError: Timed out retrying:…
beachCode
  • 3,202
  • 8
  • 36
  • 69
6
votes
1 answer

Mocking angular service class properties or variables

I am unit testing an angular application and there is a service I need to mock. I am able to mock service methods without any problem but when I try to mock properties in the same way it give me error My configuration service have one property and…
Aniruddha Das
  • 20,520
  • 23
  • 96
  • 132
5
votes
2 answers

Typescript opposite / reverse operation of "typeof"

Angular can Query subComponents by Types, which is used in Testing like this: fixture.debugElement.query( By.directive( ComponentType ) ); Now i wanted to make a function which does this for me: import { ComponentFixture } from…
5
votes
1 answer

How to exclude spec files while getting code coverage [Angular]

I'm trying to get the code coverage of my angular project. I'm not very well versed with the tools. I decided to use "istanbul-instrumenter-loader": "^3.0.1". I tried taking help from this question: angular cli exclude files/directory for ng…
5
votes
2 answers

No project support the 'test' target in Angular

I want to test Angular project with 'ng test' command, but I'm obtaining error 'No project support the test target. Does anyone know what should I add in project dependencies to run tests with mentioned command? I don't want to create another…
blackRose
  • 180
  • 1
  • 9
5
votes
3 answers

Angular 7 testing - simulate input event with debounce time

Before starting this question. I'm aware, that there are a lot of similar asked questions liked mine. But no solution was able to help me out. I created a custom auto-complete with rxjs and want to test if a method gets called on a input event. But…
MarcoLe
  • 2,309
  • 6
  • 36
  • 74
5
votes
2 answers

how to trigger input onchange from Angular spec

I have an input HTML File filed I want to unit test handleFileSelect function. But I don't know how to trigger the…
Manu Chadha
  • 15,555
  • 19
  • 91
  • 184
5
votes
1 answer

ng test gives Component should create

I have written my first angular application in Angular 6. I have not written any test yet but there are some default test files created automatically while generating components and services. When I run the auto-generated tests using ng test It…
Anuj TBE
  • 9,198
  • 27
  • 136
  • 285
5
votes
2 answers

angular unit tests - start Chrome after successful build (taking long time)

On some machines building the Angular app takes more then 2*60s (default timeout for Chrome started by Karma to catch the content). Is there a way to force Karma to start Chrome after build is finished? My package.json: { "dependencies": { …
5
votes
1 answer

How to test Angular component with Observable Input

I'm trying to test an Angular Component that basically receives an Observable and changes its template based on the values emitted from that Observable. Here's a simplified version: @Component({ selector: 'async-text', template: ` …
bengr
  • 316
  • 3
  • 8
5
votes
4 answers

How to test Material2 snack-bar?

I have a project on Angular 5 and I encountered with following issue. I have a component ComponentWithSnackBar which triggers displaying of a snack-bar: showSnackBar() { this.snackBar.open('Message text', 'Close', { duration: 5000, …