我在Jasmine中有以下代码:
it('should pass on writing secondvalue in the input', async(() => {
const fixture=TestBed.createComponent(AppComponent);
const app=fixture.debugElement.nativeElement.querySelector("input").getAttribute("value");
expect(app).toContain("firstvalue");
fixture.detectChanges();
expect(app).toContain("secondvalue");
}));
问题在于,一旦我运行测试,测试就会失败。我期望它等待detectChanges(),但它没有。
如何正确实现:等待第二个值输入到输入框中,并检查该值是否为"secondvalue"。
fixture.detectChanges()难道不应该像一个阻塞器一样工作吗?例如,当有人开始在输入框中输入时,它应该等待输入被触发吧?
fixture.detectChanges()
。此外,不太清楚你的组件是什么样子的,以及其中的值如何更改。 - Marianconst h4 = fixture.debugElement.query(By.css('h4'));
不应该改为const h2 = fixture.debugElement.query(By.css('h2'));
吗? - Anders Persson