我正在尝试通过以下方式测试是否单击了按钮:
单击按钮时,某些元素类从wrapper-container
更改为wrapper-container-expanded
(我不想检查单击按钮时是否调用了函数-这不是我的目的)
我正尝试通过以下方式对此进行检查:
it('should class be changed', ()=>{
fixture.detectChanges()
clickedElement.nativeElement.click() // click the button that causes the class change
elementToBeExpanded = fixture.debugElement.nativeElement.querySelector('wrapper-container-expanded')
expext(elementToBeExpanded).toBeTruthy() // check if the element with the new class exists in the DOM -the elementToBeExpanded is null
})
尽管我可以看到调用了函数并且更改了类,但是找不到具有新类的元素,并且旧的wrapper-container
似乎存在。
答案 0 :(得分:4)
点击事件后,您需要致电 fixture.detectChanges()
。
it('should class be changed', () => {
// ...
clickedElement.nativeElement.click() // click the button that causes the class change
fixture.detectChanges() // detect the changes!!
// ...
})