Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在单元测试中设置html输入元素的文本内容_Html_Angular_Typescript_Unit Testing - Fatal编程技术网

如何在单元测试中设置html输入元素的文本内容

如何在单元测试中设置html输入元素的文本内容,html,angular,typescript,unit-testing,Html,Angular,Typescript,Unit Testing,我正在运行angular应用程序的单元测试,我想通过单元测试设置此输入元素的文本内容。我正在使用jasmine <input type="text" id="accountid" class="form-control col-sm-3" [(ngModel)]="record.accountid" name="accountid" required> 在设置输入的值后,必须发送事件: let formData = fixture.debugElement.query(By.css

我正在运行angular应用程序的单元测试,我想通过单元测试设置此输入元素的文本内容。我正在使用jasmine

<input type="text" id="accountid" class="form-control col-sm-3" [(ngModel)]="record.accountid" name="accountid" required>

在设置
输入的值后,必须发送
事件:

let formData = fixture.debugElement.query(By.css('#accountid'));
    formData.nativeElement.value = 22;
    formData.nativeElement.dispatchEvent(new Event('input'));

expect(formData.nativeElement.value).toBe(22);

谢谢Chrillewoodz,但它没有设置输入元素的文本内容,在每个语句后都尝试fixture.detectchanges,不是吗work@karansys我不认为你应该测试
textContent
,而是测试值。谢谢:)这样行吗,你能编辑你的答案吗,所以我会把它标记为正确的
let formData = fixture.debugElement.query(By.css('#accountid'));
    formData.nativeElement.value = 22;
    formData.nativeElement.dispatchEvent(new Event('input'));

expect(formData.nativeElement.value).toBe(22);