我需要对一个填充格式的输入元素进行单元测试,当填充其他字段时将禁用该元素

问题描述 投票:0回答:1

我有一个angular8材质的mat-form-field,其输入类型='text',当在该表单上的任何其他字段中输入数据时,该字段将被禁用。

const fnDe: DebugElement = fixture.debugElement.query(By.css('input[type=text]')).nativeElement;
expect(fnDe.attributes).toContain['disabled'];

运行测试时,我收到'SPEC HA EXPECTATIONS'消息。

我正在使用angular8。

感谢任何帮助。

typescript jasmine angular-material karma-runner
1个回答
0
投票

首先请注意,在您的代码中,fnBe不是DebugElement,而是本机HTML元素。从那里,您可以编写测试,如下所示:

const htmlElement: HTMLElement = fixture.debugElement.query(By.css('input[type=text]')).nativeElement;

expect(htmlElement.getAttributeNames()).toContain('disabled');

expect也可以简化:

expect(htmlElement.hasAttribute('disabled')).toBe(true);
© www.soinside.com 2019 - 2024. All rights reserved.