Questions tagged [angular-testing-library]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
26 views

Using Jest/angular-testing-library to test eventEmitter subscription return

I am coding with Angular and am attempting to write a test for the below function. We are not using the built in test and are using Jest with the angular-testing-library. When I run the test, I am not ...
  • 11
0 votes
1 answer
228 views

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....
  • 613
0 votes
1 answer
103 views

how can I test a component that have a function that use async await?

I have a problem. I have a function that use a async await to get data, but in the moment that I try test it. I don't know how to do that. I tried this this is my component async loadTodos() { try ...
0 votes
1 answer
24 views

how to get the property of behaivourSubject type property of a service ?, angular testing

I have a service like export class TestService { public props: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false); props$ = this.props.asObservable(); test(){ } } ...
0 votes
0 answers
33 views

How to fix is missing in type in test file Angular components?

I have created Angular app, and in this app I have created main component that I used two component inline main component with names Article and Header, now inline Article Component I injected service ...
  • 1
2 votes
1 answer
201 views

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?...
1 vote
1 answer
29 views

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: ...
2 votes
2 answers
811 views

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, ...
  • 119
0 votes
1 answer
718 views

cannot read properties of undefined reading subscribe testing jasmine angular

Hi I trying to test http request but , when I call a function in the ngOnInit it show me that message "cannot read properties of undefined" can somebody help me? this is my test it('xxxx',...
0 votes
1 answer
40 views

How can I test a function that use a promise?

how can I test a function that call a promise ? click() { this.todoService.getUsers().then( (resp) => { this.users = resp; }, (reject) => { console.log(...
0 votes
1 answer
327 views

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....
  • 153
1 vote
1 answer
321 views

How can I test if a method was called with toHaveBeenCalled ? angular

I have a function that update a variable, but in the coverage its show me that function as if I had not tried it. How can I test if a function was called ? This is my function changePage(event) { ...
  • 153
0 votes
0 answers
36 views

test is failing on npm test in Angular

The test is failing with error: TypeError: Cannot read property 'accountId' of undefined 89 | export function mapLines(line): ActionLineDef { 90 | return { > 91 | accountId: ...
1 vote
0 answers
101 views

How to Retrive the data value from `MAT_DIALOG_DATA` with angular testing

I am retrive the passing value to MAT_DIALOG_DATA any one help me? spec.ts: test('should check component data', async () => { const { fixture } = await render(PrintPopupComponent, { ...
  • 14.3k
0 votes
0 answers
62 views

`Falsy` check not getting the `text` value from screen

I am testing a drop down select menu. I am using @angular/testing-library. when i test the falsy getting an error like: expect(await screen.findByText('Set AM/PM')).toBeTruthy(); 136 | //falsy ...
  • 14.3k
2 votes
2 answers
1k views

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 ...
1 vote
1 answer
481 views

Angular Ag-Grid row group empty render when querying DOM elements with angular-testing-library

I have an ag-grid that contains different columns and column groups, as well as row groups. I am trying to test the DOM elements displayed in the row group using Jest and Angular Testing Library. The ...
1 vote
3 answers
569 views

ng mocks library to test form component ( template driven form )

I have been going through a ton of documentations including their own ng-mocks library here . I am relatively new to this library. PS: I know other libraries like spectator to do this, or using plain ...
1 vote
1 answer
721 views

Testing Angular Output without spying on the component instance

Let's suppose I have the following component: @Component({ selector: 'app-dumb', template: '<button (click)="increment()">Increment</button>' }) export class ...
  • 375
0 votes
1 answer
288 views

Assigning variable with getByText not works as expected

Here is my testing code with testing-library with angular. Here I am using title variable for regexp. import { render, screen } from '@testing-library/angular'; import '@testing-library/jest-dom'; ...
  • 14.3k
0 votes
1 answer
22 views

How to test a service subcription to a subject from another service

I have the following services: @Injectable({ providedIn: 'root' }) export class Service1 { dataHasChanged = new Subject(); private data1; private data2; constructor() {} getData() { ...
  • 317
1 vote
0 answers
227 views

Input type of date is not working on testing library Angular , throwing error of not found label

im trying to do this test oover an input of type date in angular using Testing Library. But keep receiving this error: TestingLibraryElementError: Unable to find a label with the text of: date-input-...
  • 1,155
3 votes
2 answers
1k views

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 ...
  • 61
0 votes
0 answers
71 views

How to unit test a service with observables using jest in angular

ServiceToBeTested please help as soon as possible.
1 vote
1 answer
422 views

AG-Grid gridReady not being called on tests with Angular and Jest

The gridReady method of the Angular AG Grid is not being called in the Jest tests. Do you know why? Here you have my test code: import {TestBed} from "@angular/core/testing"; import {...
  • 4,589
0 votes
1 answer
928 views

Angular unit testing of service using HttpClientTestingModule and HttpTestingController

I have a problem with testing my application. Mainly my problem is with URL. This is my testBed: let service: AdnimistrationSiteService; let httpClient: HttpClient let httpClientMock: ...
1 vote
1 answer
199 views

Angular-testing-library - my test is not failing when expect wrong values

I am using angular-testing-library for my component testing. when expect for fail, after setting the value, my test case not failing. any one help me? (title,newTitle - @inputs) import { render, ...
0 votes
1 answer
851 views

If 'app-user' is an Angular component and it has 'InwelcomeMsg' input, then verify that it is part of this module

I am getting an error as follows when i test the child component: 1. If 'app-user' is an Angular component and it has 'InwelcomeMsg' input, then verify that it is part of this module. on testing the ...
0 votes
1 answer
420 views

How to test ng-select using Angular testing library?

I have the below list of companies populated in an ng-select: <div class="input-group"> <ng-select role="company" id="company" class="form-control" ...
1 vote
0 answers
189 views

TypeError: Cannot read property 'paramMap' of undefined while running my angular test

I am getting an error when running my angular 2 tests. the following is the error i receive. CreateFlightComponent should send a request to create a flight TypeError: Cannot read property 'paramMap' ...
0 votes
1 answer
238 views

Angular test failing because of ngOnit statements not called

Hi I am having an angular 2 component . I have a test . my test is failing as I am getting the following error. the following is the error i recieve when i run ng test. Expected spy create to ...
0 votes
1 answer
153 views

Angular 10 test with @testing-library/angular (page) attribute method on mat-paginator

I have the <mat-paginator> element working fine, I just want to know how the heck to I test the getPaginatorData method for the (page) attribute with the @testing-library/angular library? <...
  • 97
1 vote
1 answer
1k views

How do I rerender an Angular attribute directive using testing-library

Given this very trivial attribute directive where all it does is putting text from input into innerText import { Directive, ElementRef, Input } from '@angular/core'; @Directive({ selector: '[...
  • 7,508
0 votes
1 answer
944 views

Unit test case for mat-menu with jest and @testing-library/angular

I have a Component that uses mat-menu from Angular Material UI. When I call fireEvent.click(), I get an error: TestingLibraryElementError: Unable to find role="menu" in console. This is my ...
  • 3
3 votes
0 answers
395 views

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'; ...
  • 383
2 votes
0 answers
132 views

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 ...
  • 558
0 votes
2 answers
2k views

Jest + angular-testing-library: Mock TranslateService

I'm trying to test a component using angular-testing-library and I can't figure out how to mock TranslateService from @ngx-translate My stripped down component: import { Component } from '@angular/...
  • 1,128
19 votes
3 answers
10k views

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 ...
  • 5,018
1 vote
1 answer
195 views

Using Jasmine-DOM in Angular project

I have an Angular 10 CLI project (v10.1.2). I've installed @testing-library/angular@10.0.2, and I want the nice matchers like .toBeInTheDocument(), but as I'm using Karma to run Jasmine (configured ...
  • 5,018
4 votes
0 answers
345 views

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

In my Angular app I have a <select> bound to a reactive form like the following: <form [formGroup]="myForm"> <select formControlName="myControlName" id="my-...
1 vote
0 answers
391 views

Can not find module 'ngx-store' from service.ts

currently I am running on Angular 9 ,while I am testing My Component using Jest, I am getting an error like "Can not find module 'ngx-store' from service.ts" and the code showing me which is ...
  • 11
7 votes
1 answer
2k views

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....
  • 398
-1 votes
1 answer
114 views

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) { ...
  • 14.3k
0 votes
0 answers
92 views

Writing tests with testing-library depends on implementation details of my UI library

I am using @testing-library to test my React project which uses Material-UI as it's main UI library. As @testing-library suggests, it's main philosophy is to test the application in the exact same way ...
0 votes
1 answer
947 views

How to check the emit value when it's called by mock function

I am using https://testing-library.com/ for test my angular app. Here is my component function: onCreateFormSubmit() { if (this.createForm.valid && this.crud.isCreate) { this....
  • 14.3k
0 votes
1 answer
355 views

Not able to set input value, when I use 'updateOn' attribute with form Control

I am doing testing using https://testing-library.com/ Here is my Reactive form: this.createForm = this.formBuilder.group({ 'Id': new FormControl({ value: 0, disabled: true }, [Validators.required]),...
  • 14.3k
5 votes
1 answer
2k views

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: <td *ngFor="let col of columns; ...
  • 14.3k
0 votes
1 answer
1k views

How to use input method in to ngFor loop form element

I am trying to add input value to *ngFor element. using ngFor i generate the table td's, which have the reactive form added. here is my html: <td *ngFor="let col of columns;" [ngClass]="col.class"...
  • 14.3k
0 votes
2 answers
797 views

How to find the child component existence in angular using `testing-library`

In my component.html, i am keeping some of required child component. i would like to test those existence. As well I am using CUSTOM_ELEMENTS_SCHEMA in my testbed. if I am not use that, I require to ...
  • 14.3k
3 votes
1 answer
1k views

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 ...