我的组件中有一个close函数,其中包含一个setTimeout()
,以便为动画的完成留出时间.
public close() {
this.animate = "inactive"
setTimeout(() => {
this.show = false
}, 250)
}
this.show
和ngIf
是必然的.
this.animate
绑定到动画.
我有一个测试需要测试这个功能
it("tests the exit button click", () => {
comp.close()
fixture.detectChanges()
//verifies the element is no longer in the DOM
const popUpWindow = fixture.debugElement.query(By.css("#popup-window"))
expect(popUpWindow).toEqual(null)
})
当有一个setTimeout()
时,你如何正确地测试这个功能?
我用的是jasmine.clock().tick(251)
,但windows 永远不会消失.你对此也有什么 idea 吗?