91得票4回答
Angular CLI为已经存在的组件创建.spec文件

在 .angular-cli.json 中有一个选项可以禁用自动创建组件等的 *.spec 文件,详见 json schema。 这是一个非常好的功能,因为个人认为(仅代表我的观点),在快速增长的项目中测试组件可能并不是非常必要的。 然而,有时我希望有一个选项来生成/重新创建已存在组件/服...

16得票3回答
如何在Angular单元测试中使用debugElement访问nativeElement属性

我想编写一个简单的单元测试来检查当特定值为 null 或空时,按钮是否被禁用。以下是我的规范文件:test.spec.tsimport { async, ComponentFixture, TestBed } from '@angular/core/testing'; import 'refl...

12得票2回答
Angular 4单元测试中,ngOnChanges函数未被调用,即使使用了detectChanges()方法。

问题 我有一个按钮组件,它接受一个Promise,并在Promise解决之前禁用按钮。 我想为此功能编写单元测试。 我的代码 我的按钮组件有一个用于Promise的输入。 /** * A single promise that triggers the busy state un...

11得票4回答
在Angular 4单元测试中,出现了一个错误: "afterAll中抛出了一个错误[object ErrorEvent]"

在我进行 Angular 4 单元测试时,使用了 Google 地图和 agm 包的其中一个页面出现了错误:An error was thrown in afterAll\n[object ErrorEvent] thrown 有人知道问题可能是什么吗? 控制台截图

11得票1回答
Angular单元测试:如何将FormGroup作为@Input传递

我想进行一些单元测试,其中有一个 formGroup 作为输入从父组件传递到子组件,如何操作。 app.componet.ts import { Component, Input } from '@angular/core'; import { FormGr...

11得票2回答
Angular 9 TestBed.inject和提供者覆盖

在使用提供程序重写时,由于Angular 9中TestBed.get已被弃用,以下内容现在有哪些替代方案?TestBed.configureTestingModule({ providers: [{ provide: MyClass, useClass: MyStub}] }); con...

10得票2回答
如何对@viewChild ElementRef angular进行单元测试

我的组件文件有以下代码 @ViewChild('clusterCard', { static: false }) clusterCard: ElementRef; highLightTheClusterCard(point: PickupClusterPoint) { if (...

10得票2回答
Angular测试错误-NullInjectorError:未提供TrimInputDirective的提供程序。

我创建了一个Angular指令,该指令使用CSS选择器自动修剪应用程序中的输入,它看起来像这样... import { Directive, HostListener, forwardRef } from '@angular/core'; import { DefaultValueAcces...

8得票7回答
Angular Universal 中 ng test 失败,报错信息为 "Incomplete: No specs found, , randomized with seed 48751"。

在运行"ng test"命令时,将Angular 7项目转换为Angular Universal却出现错误,错误信息为"Incomplete: No specs found, , randomized with seed 48751"。我在stackoverflow上尝试了不同的方法,但都没有...