Questions tagged [angular-testing-library]

51 questions
20
votes
3 answers

Stop huge error output from testing-library

I love testing-library, have used it a lot in a React project, and I'm trying to use it in an Angular project now - but I've always struggled with the enormous error output, including the HTML text of the render. Not only is this not usually helpful…
Ian Grainger
  • 5,148
  • 3
  • 46
  • 72
7
votes
1 answer

angular-testing-library: getByRole query works only with hidden: true option

I am just trying out this library and seem to be unable to access elements by their ARIA role. I use angular 10.0.6, jest 26.2.1 together with jest-preset-angular 8.2.1 and @testing-library/angular 10.0.1. I believe to have set the project up as…
Chris
  • 408
  • 2
  • 10
6
votes
1 answer

ngFor - Can't bind to 'testid' since it isn't a known property of 'input'. how to concat id with string?

I am trying to add the index value with my ids. but getting an error as: Can't bind to 'testid' since it isn't a known property of 'input'. here is my template:
4
votes
0 answers

How to get the value of a select when using ngValue in Angular unit tests

In my Angular app I have a
3
votes
2 answers

How to test Custom Elements / Web Components with Testing-Library, Jest and JSDOM?

I am trying to test an Angular app with testing-library/angular@11 and jest@27.4.4 which uses custom-elements quite heavily. Unfortunately I am not quite sure if testing-library/JSDOM/Jest just don't support the rendering of custom-elements or if I…
3
votes
0 answers

Angular Unit Test: This constructor is not compatible with Angular Dependency Injection

I'm trying to write an Angular unit test (using the Angular Testing Library) and get a strange error. This is the component I want to test: import { Component, Inject, OnInit } from '@angular/core'; import { MatDialogRef, MAT_DIALOG_DATA } from…
Jer
  • 383
  • 3
  • 17
3
votes
1 answer

Injecting mock services with @testing-library/angular

I am trying to test an angular component using @testing-library/angular by Kent C Dodds. My component has a dependency on an Angular service. I see no information in the api docs on how to inject a mock service to provide mock data for my unit…
2
votes
0 answers

matching versions between angular testing library and angular core

I am using Angular 14, when trying to use the last version of the angular-testing-library, today 14.0.0, it was not working because this latest version only works with Angular 15. This is due to the isStandalone vs eisStandalone breaking change in…
Pipeio
  • 21
  • 1
2
votes
1 answer

Angular 14 + Jest - typescript_1.default.canHaveDecorators is not a function

After configuring Jest with Angular 14, I'm getting this error: Test suite failed to run TypeError: typescript_1.default.canHaveDecorators is not a function at TypeScriptReflectionHost.getDecoratorsOfDeclaration…
2
votes
1 answer

The fireEvent.click() from @testing-library/angular not working for 'ion-button' component but works for normal button

I am developing an application with Ionic Angular. While I am testing with @testing-library/angular, the test is not working for ion-button but works for normal button field. What could be the problem? fireEvent.click() event is not working for the…
2
votes
2 answers

Angular unit test mock parent component on child component

I'm trying to test the child component, but it requires a parent component for its main functionalities. How can I test the child component with a "mock" parent? (Using Jest, Angular 14, TypeScript) parent.component.ts @Component({...}) export class…
Doug
  • 129
  • 1
  • 12
2
votes
2 answers

TypeError: (0 , import_core.ɵisStandalone) is not a function

I tried to use jest with Angular 13 using this tutorial and I got this error bellow. I don't understand why this error appear, and what it's missing / not working. I have done those steps : ng n test-jest --style scss --routing -g true -S ng g c…
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
1
vote
1 answer

Error in tests with Angular 6 and Jest - TypeError: testing.TestBed.inject is not a function

When running the tests on my project when trying to render the component, the tests fail with the following error: TypeError: testing.TestBed.inject is not a function This is the test component: import { Component, Input } from…
1
vote
1 answer

How can I test if a @output emit a value?

I have a component that emit a value when call to a function, how can I test if the @output emit a value ? this is my function @Output() emitDetail = new EventEmitter(); emitDetailFn() { this.emitDetail .emit(false); } and this is my test …
1
2 3 4