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

How to test an Angular component that injects an AngularJS service

I am running a hybrid angular application. Most of my services are still on the AngularJS side. I am able to use those in my hybrid application just fine. export function myServiceFactory(i: any): any { return i.get('MyService'); } export const…
lostintranslation
  • 23,756
  • 50
  • 159
  • 262
-1
votes
1 answer

DebugElement, By.css, nativeElement and.querySelector in Angular 11

The code below is from the link below. https://angular.io/guide/testing-components-basics#bycss The server-side renderer might not support the full HTML element API. If it doesn't support querySelector, the previous test could fail. The…
Pingpong
  • 7,681
  • 21
  • 83
  • 209
-1
votes
1 answer

Is there any way to render two Angular components in the same jasmine file?

I would like to pretend an integration test with two angular components, in order to do that, I need render both. Can we do that? Is a good practice?
-1
votes
1 answer

Getting the error of NullInjectorError: No provider for HttpClient! in angular testing

While running the ng test in angular I am getting the error as SidebarComponent > should create NullInjectorError: R3InjectorError(DynamicTestModule)[AuthserviceService -> HttpClient -> HttpClient]: NullInjectorError: No provider for…
-1
votes
1 answer

What can be the reason for the error with render2 dependency injection?

I get the error below, for angular attribute testing when runningng test. No captured browser, open http://localhost:9876/ 03 01 2021 19:23:43.285:INFO [karma-server]: Karma v5.0.9 server started at http://0.0.0.0:9876/ 03 01 2021 19:23:43.286:INFO…
-1
votes
2 answers

Angular tour-of-heroes: no provider for HttpClient when testing a component

I've seen many threads about this error but in my case, I don't have any error with the hero.service.spec.ts (at least, nothing shows up) but I have the No provider for HttpClient when I test a component which depends on the Hero service (the Hero…
ValLeNain
  • 2,232
  • 1
  • 18
  • 37
-1
votes
3 answers

TypeError: (options.astTransformers || []).map is not a function angular 10

I have a unit test running using the "jest": "^26.4.2", "jest-preset-angular": "^8.3.1", When I run the command npm run test:app it was working fine in Angular 8, now I have updated the angular to the latest version 10. I am getting an error as…
San Jaisy
  • 15,327
  • 34
  • 171
  • 290
-1
votes
1 answer

angular testing a component using jasmine when the a method call is made in the html

I have to test this odd situation. In my html i have:
{{ showFormattedDate(myDate) }}
The function showFormattedDate() is defined in .ts as follows: showFormattedDate(dateToFormat:…
user11480180
-1
votes
1 answer

How to test the private methods/declarations using "testing-library"

Is there any way to test the private method or declaration using "testing-library" framework in angular? here is my code: priave name = "somename" private setLang(url: string, fetch: boolean) { switch (url) { case '/SSB/mngt': …
3gwebtrain
  • 14,640
  • 25
  • 121
  • 247
-1
votes
1 answer

Angular 7 Unit testing - PhantomJS has crashed

I am using Angular 7 for unit testing using karma and phantom JS. While I have run from my local machine, from my MAC -- ng test --watch=false Local Machine Output - ng test 10% building modules 2/2 modules 0 active18 01 2020 14:54:57.990:WARN…
Atique Ahmed
  • 308
  • 4
  • 16
-1
votes
1 answer

Integration tests in Angular application

I am a bit confused about this test: describe('#getUsers', () => { it('should return an Observable', () => { const dummyUsers: User[] = [ new User(0, 'John'), new User(1, 'Doe') ]; …
tylkonachwile
  • 2,025
  • 4
  • 16
  • 28
-2
votes
1 answer

Expecting method call from another method failing on test

Here is the function: handleAddClinic() { HFSClinicTableSchema.headers.map((th) => th.checked ? (th.checked = false) : th ); this.popTableSchema = { ...HFSClinicTableSchema, rows: [] }; …
3gwebtrain
  • 14,640
  • 25
  • 121
  • 247
-4
votes
1 answer

Karma tests randomly restart and "double" iframe in Edge

I have a suite of Karma/Jasmine tests for my Angular 7 app. All my tests pass in Chrome and Firefox, but when I run them in Edge it will run for a little bit and then sometimes it will randomly reload the page and start over, and sometimes it will…
Chris Barr
  • 29,851
  • 23
  • 95
  • 135
1 2 3
47
48