rxjs

Nest JS - Issue writing Jest Test Case for a function returning Observable Axios Response

只愿长相守 提交于 2021-01-05 06:18:04
问题 I am fairly new to NestJS + Typescript + RxJs tech stack. I am trying to write a unit test case using Jest for one of my functions but not sure if doing it correctly. component.service.ts public fetchComponents(queryParams) { const url = this.prepareUrl(queryParams); const data$ = this.httpService.get(url); return data$ .pipe(map(({ data }) => data)); } component.sevice.spec.ts Test case works and passes describe('fetchComponents', () => { const query = { limit: 10, offset: 0 }; const result:

Angular 6 wait for subscribe to finish

落花浮王杯 提交于 2021-01-03 07:32:44
问题 I have function like: getNumber(value) { this.myService.getApi(value).subscribe(data => { this.myVariable = data; }); } And I am calling that function in other function as follows : set() { if (this.value == 1) { this.getNumber(firstNumber) this.newVariable = this.myVariable; } else { this.getNumber(secondNumber) this.newVariabe = this.myVariable + 1; } }; this.value is getting from other function. The problem is that this.newVariable is empty. I'm sure this is because the subscribe hasn't

Subject call to next causing a strange error

青春壹個敷衍的年華 提交于 2021-01-01 08:56:26
问题 This causes the following error: Cannot read property 'length' of undefined const msg$ = new Subject<string>(); msg$.subscribe(console.log) of("Hello").subscribe(msg$.next); If, however, I wrap msg$.next in a function, then it works without any errors. Lambda function const msg$ = new Subject<string>(); msg$.subscribe(console.log) of("Hello").subscribe(greeting => msg$.next(greeting)); Anonymous function const msg$ = new Subject<string>(); msg$.subscribe(console.log) of("Hello").subscribe

Subject call to next causing a strange error

ε祈祈猫儿з 提交于 2021-01-01 08:55:05
问题 This causes the following error: Cannot read property 'length' of undefined const msg$ = new Subject<string>(); msg$.subscribe(console.log) of("Hello").subscribe(msg$.next); If, however, I wrap msg$.next in a function, then it works without any errors. Lambda function const msg$ = new Subject<string>(); msg$.subscribe(console.log) of("Hello").subscribe(greeting => msg$.next(greeting)); Anonymous function const msg$ = new Subject<string>(); msg$.subscribe(console.log) of("Hello").subscribe

Angular RxJS - How to monitor progress of HTTP Get Request (not file)

谁说胖子不能爱 提交于 2020-12-31 05:23:07
问题 How to utilize Angular HTTPClient's progress event to show progress in percentage of Get request which does not necessarily a file request? Currently HTTPClient's progress event fires after request completion. I am hoping to work with Content-Length at back end and determine percentage of content loaded at front end. I am loading a large amount of rows for a grid and need to show incremental progress on UI. Is it possible? 回答1: I know this question is older but, i stumbled upon this while

Angular/Rxjs pipe async does not work with ssr?

三世轮回 提交于 2020-12-30 17:35:52
问题 I have an issue with the async pipe running on SSR. there are no errors, only an infinite loop (it seems that the server is waiting for the observable to be resolved). I am using: @nestjs/ng-universal Angular 9 Firebase Rxjs A simple case like this works: <p>{{ observable | async }}</p> But using structural directives do not work: ngIf <p *ngIf="(observable$ | async) > 5">{{ observable$ | async }}</p> Ngfor <p *ngFor="let item of items | async">{{ item }}</p> Using async is a good practice

Angular/Rxjs pipe async does not work with ssr?

时光毁灭记忆、已成空白 提交于 2020-12-30 17:29:14
问题 I have an issue with the async pipe running on SSR. there are no errors, only an infinite loop (it seems that the server is waiting for the observable to be resolved). I am using: @nestjs/ng-universal Angular 9 Firebase Rxjs A simple case like this works: <p>{{ observable | async }}</p> But using structural directives do not work: ngIf <p *ngIf="(observable$ | async) > 5">{{ observable$ | async }}</p> Ngfor <p *ngFor="let item of items | async">{{ item }}</p> Using async is a good practice

Angular/Rxjs pipe async does not work with ssr?

妖精的绣舞 提交于 2020-12-30 17:25:32
问题 I have an issue with the async pipe running on SSR. there are no errors, only an infinite loop (it seems that the server is waiting for the observable to be resolved). I am using: @nestjs/ng-universal Angular 9 Firebase Rxjs A simple case like this works: <p>{{ observable | async }}</p> But using structural directives do not work: ngIf <p *ngIf="(observable$ | async) > 5">{{ observable$ | async }}</p> Ngfor <p *ngFor="let item of items | async">{{ item }}</p> Using async is a good practice

Angular/Rxjs pipe async does not work with ssr?

此生再无相见时 提交于 2020-12-30 17:21:31
问题 I have an issue with the async pipe running on SSR. there are no errors, only an infinite loop (it seems that the server is waiting for the observable to be resolved). I am using: @nestjs/ng-universal Angular 9 Firebase Rxjs A simple case like this works: <p>{{ observable | async }}</p> But using structural directives do not work: ngIf <p *ngIf="(observable$ | async) > 5">{{ observable$ | async }}</p> Ngfor <p *ngFor="let item of items | async">{{ item }}</p> Using async is a good practice

Angular/Rxjs pipe async does not work with ssr?

北城以北 提交于 2020-12-30 17:20:42
问题 I have an issue with the async pipe running on SSR. there are no errors, only an infinite loop (it seems that the server is waiting for the observable to be resolved). I am using: @nestjs/ng-universal Angular 9 Firebase Rxjs A simple case like this works: <p>{{ observable | async }}</p> But using structural directives do not work: ngIf <p *ngIf="(observable$ | async) > 5">{{ observable$ | async }}</p> Ngfor <p *ngFor="let item of items | async">{{ item }}</p> Using async is a good practice