我想编写一个测试,以检查在单击页面后该页面上是否存在元素。因此,当我单击类为“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();
});
但上面写着:
Property 'toExist' does not exist on type 'Matchers<DebugElement>'.
你能告诉我怎么做吗?多谢!
最佳答案
我建议你用
// Add Item Debug Ele comes out as null.
addItemDebugElement = componentFixture.debugElement.query(By.css('.addItem'));
expect(addItemDebugElement).toBeFalsy();
还有…
// Add Item Debug Ele comes out as not null.
addItemDebugElement = componentFixture.debugElement.query(By.css('.addItem'));
expect(addItemDebugElement).toBeTruthy();
关于angular - 检查元素是否存在- Jasmine 和 Angular ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49053890/