【发布时间】:2019-02-18 21:09:07
【问题描述】:
我正在尝试测试通过键盘输入哪个值的事件。我的问题是在为输入字段设置值之后,当我打印它时,当我在 whenStable() 中打印它时,它打印为空。我想知道为什么这个值会在 Whitstable() 函数中被重置。我该如何解决?
我已推荐:Updating input html field from within an Angular 2 test 编写此测试用例。
it('Test input field value. ', async () => {
const divDescription = fixture.debugElement.query(By.css('#costDescription'));
divDescription.nativeElement.value = 'text';
divDescription.nativeElement.dispatchEvent(new Event('input'));
fixture.detectChanges();
console.log('sendInput : ', divDescription.nativeElement.value); // prints 'text'
fixture.whenStable().then(() => {
console.log('sendInput : ', divDescription.nativeElement.value); // prints ''
expect(divDescription.nativeElement.value).toContain('text');
});
});
【问题讨论】:
标签: javascript angular unit-testing karma-jasmine