angular-test

Test pipe with dependencies on services

泄露秘密 提交于 2019-12-02 20:29:05
I have a pipe that sanatises HTML as below: import { Pipe, PipeTransform } from '@angular/core'; import { DomSanitizer } from '@angular/platform-browser'; @Pipe({ name: 'sanitiseHtml' }) export class SanitiseHtmlPipe implements PipeTransform { constructor(private _sanitizer: DomSanitizer) {} transform(value: any): any { return this._sanitizer.bypassSecurityTrustHtml(value); } } I want to test it as below: describe('Pipe: Sanatiser', () => { let pipe: SanitiseHtmlPipe; beforeEach(() => { pipe = new SanitiseHtmlPipe(new DomSanitizer()); }); it('create an instance', () => { expect(pipe)

angular e2e testing : how to test Service inject(use) another services

一曲冷凌霜 提交于 2019-12-02 15:35:50
问题 i'm trying to test my service with e2e test angular 7, my problem is i don't know how to do that: it's my service, (the methode return Observable): import { Injectable } from '@angular/core'; import { UrlDecoratorService } from "../../common/url-decorator.service"; import { APIFetcherService } from "../common/api-fetcher.service"; import { Observable } from 'rxjs'; import { IALChrono, ALChrono } from '../../common/IALChrono.interface'; @Injectable() export class AnnonceChronoDetailService {

angular e2e testing : how to test Service inject(use) another services

好久不见. 提交于 2019-12-02 08:33:38
i'm trying to test my service with e2e test angular 7, my problem is i don't know how to do that: it's my service, (the methode return Observable): import { Injectable } from '@angular/core'; import { UrlDecoratorService } from "../../common/url-decorator.service"; import { APIFetcherService } from "../common/api-fetcher.service"; import { Observable } from 'rxjs'; import { IALChrono, ALChrono } from '../../common/IALChrono.interface'; @Injectable() export class AnnonceChronoDetailService { private months: string[]; constructor(private urlDecoratorService: UrlDecoratorService, private

Test subscribing to Location in angular 2 with karma+jasmine (this.location.subscribe)

萝らか妹 提交于 2019-12-02 04:03:45
问题 I am subscribing to the angular Location service in my component as such: this.location.subscribe((ev:PopStateEvent) => { this.lastPoppedUrl = ev.url; }); I'd like to be able to test it along with the rest of my component. Right now I have this stub in my component.spec.ts file let locationStub: Partial<Location>; locationStub = { } And I am configuring it into my TestBed as a provider: {provide: Location, useValue: locationStub } When I run ng test , I get this error this.location.subscribe

Angular Cypress.io test with Google Login popup window

不打扰是莪最后的温柔 提交于 2019-12-01 05:32:55
问题 Is it possible to login to a Google account with Cypress.io using the Google authentication pop-up window? I can get the window to open, but then Cypress can't detect the ID for the email input field. The error is: "CypressError: Timed out retrying: Expected to find element: '#identifierId', but never found it." it('Login', function() { cy.visit('home') cy.get('#signin-button').click() cy.get('#google-login-button').click() // cy.wait(1500) // wait doesn't help cy.get('#identifierId') .type(

Angular 2 Testing - Async function call - when to use

醉酒当歌 提交于 2019-11-27 04:09:16
When do you use the async function in the TestBed when testing in Angular 2? When do you use this? beforeEach(() => { TestBed.configureTestingModule({ declarations: [MyModule], schemas: [NO_ERRORS_SCHEMA], }); }); And when do you use this? beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [MyModule], schemas: [NO_ERRORS_SCHEMA], }); })); Can anyone enlighten me on this ? Paul Samsotha async will not allow the next test to start until the async finishes all its tasks. What async does is wrap the callback in a Zone, where all asynchronous tasks (e.g. setTimeout ) are

Angular 2 Testing - Async function call - when to use

独自空忆成欢 提交于 2019-11-26 10:59:49
问题 When do you use the async function in the TestBed when testing in Angular 2? When do you use this? beforeEach(() => { TestBed.configureTestingModule({ declarations: [MyModule], schemas: [NO_ERRORS_SCHEMA], }); }); And when do you use this? beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [MyModule], schemas: [NO_ERRORS_SCHEMA], }); })); Can anyone enlighten me on this ? 回答1: async will not allow the next test to start until the async finishes all its tasks. What async