检查元素是否存在 – Jasmine&Angular
发布时间:2020-12-17 07:16:40 所属栏目:安全 来源:网络整理
导读:我想编写一个测试来检查点击后页面上是否存在元素.因此,当我单击带有“addItem”类的元素时,使用* ngIf隐藏此元素.我试过这样的: it('Should handle click on .addItem button',() = { spyOn(component,'addItem'); addItemDebugElement = componentFixture
我想编写一个测试来检查点击后页面上是否存在元素.因此,当我单击带有“addItem”类的元素时,使用* ngIf隐藏此元素.我试过这样的:
it('Should handle click on .addItem button',() => { spyOn(component,'addItem'); addItemDebugElement = componentFixture.debugElement.query(By.css('.addItem')); addItemDebugElement.nativeElement.click(); // click on the button expect(addItemDebugElement).toExist(); }); 但它说:’Matchers< DebugElement>‘类型中不存在属性’toExist’. 解决方法
您可以尝试这个来检查Dom上是否存在该元素
expect($(document)).toContain(addItemDebugElement) 要么 expect(addItemDebugElement).toBeInDom(); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |