angular-test

Angular Effects - how to get 100 percent test result (coverage in funcs )?

亡梦爱人 提交于 2021-02-11 13:40:51
问题 here is my effects: import { Injectable } from '@angular/core'; import { Action } from '@ngrx/store'; import { Actions, createEffect, ofType } from '@ngrx/effects'; import { of, Observable } from 'rxjs'; import { catchError, map, switchMap } from 'rxjs/operators'; import * as courseAttributeActions from '../actions/candidate-registration-management.action'; import { CandidateRegistrationManagementService } from '../../services/candidate-registration-management.service'; @Injectable() export

Why checkbox checked property doesn't change after detectChanges()

一个人想着一个人 提交于 2021-01-29 04:00:34
问题 I try to change checkbox checked property by changing model but it doesn't work. I cannot understand this behavior. Template : <input type="checkbox" [(ngModel)]="model"/> Testing Code : it('should be checked after click on unchecked checkbox', () => { const checkbox: HTMLInputElement = fixture.nativeElement.querySelector('input'); component.model = true; fixture.detectChanges(); expect(checkbox.checked).toBeTruthy(); }); Full code: https://stackblitz.com/edit/angular-testing-checkbox?file

Angular Testing Getting Actual HTTP Response

别说谁变了你拦得住时间么 提交于 2021-01-27 19:46:29
问题 I'm new to angular unit testing. What I want to do is getting actual results from my API. I checked this documentation but as I understand, I should create mock responses. Here is my code, myService.ts: ... public GetAll = (apiname: string): Observable<Object> => { return this._http.get("foo/" + apiname,{headers:this.options}); //this.options = newHttpHeaders({'ContentType':'application/json','Accept':'application/json'}); } ... myService.spec.ts: ... beforeEach(() => { TestBed

When to use waitForAsync in angular

喜你入骨 提交于 2020-12-13 03:34:13
问题 From documentation we can read: waitForAsync(fn: Function): (done: any) => any Wraps a test function in an asynchronous test zone. The test will automatically complete when all asynchronous calls within this zone are done. Can be used to wrap an inject call. I could not understand, when to use waitForAsync function? What's the difference between waitForAsync vs ( async or fakeAsync )? 回答1: In Angular 10.1.0, waitForAsync() has replaced async() to avoid confusion, but is otherwise exactly the

When to use waitForAsync in angular

痴心易碎 提交于 2020-12-13 03:31:59
问题 From documentation we can read: waitForAsync(fn: Function): (done: any) => any Wraps a test function in an asynchronous test zone. The test will automatically complete when all asynchronous calls within this zone are done. Can be used to wrap an inject call. I could not understand, when to use waitForAsync function? What's the difference between waitForAsync vs ( async or fakeAsync )? 回答1: In Angular 10.1.0, waitForAsync() has replaced async() to avoid confusion, but is otherwise exactly the