玩笑/旁观者 spyOn ChangeDetectorRef

时间:2021-07-15 00:11:13

标签: angular-spectator angular-jest

在我的 angular 12 应用程序中,我为我的组件使用了一个 A B C D E F g h * 2 1 5 g i i - - 3 h q i 4 - - g h t - - 6 ,然后我通过构造函数注入了一个 ChangeDetectionStrategy.OnPush。我想测试我的方法并确保我检测到变化。它总是告诉我它没有被调用。

ChangeDetectorRef

我不知道如何检查是否被调用,因为 spies 似乎不能很好地与 ChangeDetectorRef 配合使用。我试过的是这样的:

searchLabsByTextField(): void {
    this.roomService.search(this.searchText).subscribe({
        next: x => {
            ...
            this.cdr.detectChanges()
        }
    })
}

0 个答案:

没有答案