Questions tagged [angular-testing-library]

51 questions
0
votes
1 answer

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 covering…
0
votes
1 answer

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 { const todosData = await…
0
votes
1 answer

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 = new BehaviorSubject(false); props$ = this.props.asObservable(); test(){ } } and this is my .spect file of my component let component:…
0
votes
0 answers

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 whit name ArticleService now I want to create…
fardad
  • 1
  • 7
0
votes
1 answer

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

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(reject); } ); } I tried this , but the console…
0
votes
1 answer

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'; import { AppComponent } from…
3gwebtrain
  • 14,640
  • 25
  • 121
  • 247
0
votes
1 answer

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() { return { data1: this.data1, data2:…
asotos
  • 327
  • 3
  • 14
0
votes
0 answers
0
votes
1 answer

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: HttpTestingController; let helper : Helper; …
0
votes
1 answer

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 component. i am using testing-library for angular…
0
votes
1 answer

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 have been called with […
Starbucks Admin
  • 585
  • 1
  • 8
  • 21
0
votes
1 answer

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

I have the 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?
0
votes
1 answer

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 test case: test('it should open pages menu on button click',…
0
votes
2 answers

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/core' import { TranslateService } from…
Alon Dahari
  • 1,138
  • 1
  • 9
  • 27