angular-test

Angular testing - observable pipe is not a function

回眸只為那壹抹淺笑 提交于 2020-05-30 07:13:42
问题 I want to write a unit test for a photo-upload-mehtod. But I get the Failed: this.task.snapshotChanges(...).pipe is not a function TypeError: this.task.snapshotChanges(...).pipe is not a function Error. For the sake of simplicity of this question, I put the code all in one method: Component public startUpload(event: FileList) { const file: File = event.item(0); const pathRef = `users/${this.uid}`; this.task = this.service.uploadPhoto(pathRef, file); this.fileRef = this.service

No provider for $injector in Angular Testing

若如初见. 提交于 2020-05-15 00:52:33
问题 I've been trying to setup testing in our Hybrid AngularJS/NG6 App but wow is this difficult to do. I keep getting constant errors. The latest is the following: Error: StaticInjectorError(DynamicTestModule)[$injector]: StaticInjectorError(Platform: core)[$injector]: NullInjectorError: No provider for $injector! I have the following component : import { Component, OnInit, Input, Inject } from '@angular/core'; import { DashboardService } from '../../services/dashboard/dashboard.service';

How to mock ControlContainer in angular unit test?

只愿长相守 提交于 2020-05-13 10:49:22
问题 How can I mock a ControlContainer instance so that I can test my component? I have a child component that injects a ControlContainer into the constructor, so its usage is <acr-score-card formGroupName="score"></acr-score-card> and the component itself is @Component({ selector: 'acr-score-card', templateUrl: './score-card.component.html', styleUrls: ['./score-card.component.scss'] }) export class ScoreCardComponent implements OnInit { ... form: FormGroup; constructor(private ngControl:

Angular Unit Testing - Verify emitted value from an observable using marble testing

ⅰ亾dé卋堺 提交于 2020-04-18 03:45:23
问题 I'm creating some unit tests for an Angular application that I have. I have managed to test services that make HTTP calls without any problems. I now moved to a different kind of service, which is shown below. Code import { Injectable } from '@angular/core'; import { Observable, Subject } from 'rxjs'; import { UICoupon } from '../models'; @Injectable() export class ClaimCouponService { hasClaimedCoupons = false; claimedCoupons: UICoupon[] = []; onClaimCoupons: Observable<UICoupon[]>; private

how to trigger input onchange from Angular spec

情到浓时终转凉″ 提交于 2020-01-24 23:15:48
问题 I have an input HTML File filed <input type="file" class="custom-file-input" id="question-file-upload" formControlName="image" (change)="handleFileSelect($event)"> I want to unit test handleFileSelect function. But I don't know how to trigger the onChange method of the input. Following is the spec I have written but I get error imageInputNE.onchange is not a function fit('should keep track of image counter when an image is loaded', () => { let newPracticeQuestionComponent = component; expect

how to trigger input onchange from Angular spec

China☆狼群 提交于 2020-01-24 23:14:26
问题 I have an input HTML File filed <input type="file" class="custom-file-input" id="question-file-upload" formControlName="image" (change)="handleFileSelect($event)"> I want to unit test handleFileSelect function. But I don't know how to trigger the onChange method of the input. Following is the spec I have written but I get error imageInputNE.onchange is not a function fit('should keep track of image counter when an image is loaded', () => { let newPracticeQuestionComponent = component; expect

How to unit test Promise catch using Jasmine

旧街凉风 提交于 2020-01-06 14:00:33
问题 I have a very simple function load() that I'm trying to unit test with Jasmine. this.service.loadObject() returns a Promise. How can I test that this.logService.error will be called if the Promise is rejected ? load() { this.service.loadObject().then(x => { this.variable = x; }).catch(ex => this.logService.error(ex)); } 回答1: Something like this should work: it("should catch the error", done => { spyOn(service, "loadObject").and.returnValue(Promise.reject("test error")); spyOn(logService,