angular-unit-test

ng test fails in angular universal Error “Incomplete: No specs found, , randomized with seed 48751”

故事扮演 提交于 2021-02-08 15:00:36
问题 convert angular 7 project into angular universal while running "ng test" command giving error as " Incomplete: No specs found, , randomized with seed 48751 ". Tried different ways mention over stackoverflow but nothing work for me. ERROR in ./src/polyfills.ts Module build failed (from ./node_modules/@ngtools/webpack/src/index.js): Error: ../src/polyfills.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property. at

ng test fails in angular universal Error “Incomplete: No specs found, , randomized with seed 48751”

谁说我不能喝 提交于 2021-02-08 15:00:25
问题 convert angular 7 project into angular universal while running "ng test" command giving error as " Incomplete: No specs found, , randomized with seed 48751 ". Tried different ways mention over stackoverflow but nothing work for me. ERROR in ./src/polyfills.ts Module build failed (from ./node_modules/@ngtools/webpack/src/index.js): Error: ../src/polyfills.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property. at

Type assertion using the '<>' is forbidden,use 'as' instead?

青春壹個敷衍的年華 提交于 2020-03-16 09:18:37
问题 I have the following test case in my spec, it (should create,()=>{ const url = (<jasmine.spy> http.get).calls.args(0)[0] expect(url).toBe('/api/get') }); When I run it, I am getting the following lint error. Type assertion using the '<>' is forbidden, use as instead? Can anyone please suggest help. 回答1: From Type Assertion. Type assertions as foo vs. <foo> Originally the syntax that was added was <foo> . This is demonstrated below: var foo: any; var bar = <string> foo; // bar is now of type

Angular, unit testing a component that creates a service via an interface

喜你入骨 提交于 2019-12-13 04:36:11
问题 Given this component that creates a service locally @Component({ <removed for clarity> providers: [ { provide: 'IMyService', useClass: MyService }, ] }) export class MyComponent implements OnInit, OnDestroy, AfterViewInit { constructor(private data: IMyService){} } I've been trying to supply the service in the unit test, something like this beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [MyComponent], providers: [ { provide: 'IMyService', useClass: MockMyService }, ]

Angular 6 Unit Test ngOnInit with a setTimeOut not working

蹲街弑〆低调 提交于 2019-12-12 10:21:27
问题 I have a component with a setTimeOut function inside a ngOnInit function. To write unit test cases for that I'm using tick and fakeAsync to fast forward the setTimeOut. But, it's not getting executed which in turn is not calling other function closeAlert(). Component code: export class BannerComponent implements OnInit { @Input()errorData: any; @Input()callback: any; @Input()autoHide: boolean; constructor() { } ngOnInit() { if (this.autoHide) { setTimeout (() => { this.closeAlert(); }, 500);

angular httpClientTestingModule httpMock giving error: found 2 requests

懵懂的女人 提交于 2019-12-06 14:47:56
问题 I have written first test to test service class: service class: import { Injectable } from '@angular/core'; import {HttpClient} from '@angular/common/http' import {IComment} from "../../models/comments"; import {Observable} from "rxjs/observable"; import { mergeMap } from 'rxjs/operators'; @Injectable() export class CommentsDataService { public _url:string = "../../../../assets/json/comments.json"; constructor(private http: HttpClient) { } /** * Return Sample json for * Comment listing. *

angular httpClientTestingModule httpMock giving error: found 2 requests

谁都会走 提交于 2019-12-04 20:31:28
I have written first test to test service class: service class: import { Injectable } from '@angular/core'; import {HttpClient} from '@angular/common/http' import {IComment} from "../../models/comments"; import {Observable} from "rxjs/observable"; import { mergeMap } from 'rxjs/operators'; @Injectable() export class CommentsDataService { public _url:string = "../../../../assets/json/comments.json"; constructor(private http: HttpClient) { } /** * Return Sample json for * Comment listing. * @returns {json) */ getComments():Observable<IComment> { return this.http.get<IComment>(this._url) } /** *

Angular CLI create .spec files for already existing components

假如想象 提交于 2019-11-30 06:50:34
问题 There is an option in .angular-cli.json to disable the automatic creating of *.spec files e.g. for components, see json schema. This is a really nice feature because personally (this is just my opinion) testing the components might not be the thing that really worth it in a fast growing project. However sometimes I would like to have an option to generate / recreate the corresponding *.spec file for an already existing component / service / pipe / whatsoever. Is that possible using some