我正在表单字段的弹出窗口中加载数据。当我运行它时,输入区域填充有正确的字符串,但是当我尝试对其进行测试时-它为空''。测试期间未使用服务。
HTML
<p>
Receiver currency Xpath:
<mat-form-field appearance="outline" class="fields">
<input #toCurrencyXpath name="toCurrencyXpath"
(blur)="update(toCurrencyXpath.value)"
type="text"
matInput
[(ngModel)]="data.toCurrencyXpath">
</mat-form-field>
</p>
TyepScript
bank = {
name: 'Nordea',
country: 'DK',
pageurl: 'http://n.dk',
buyxpath: 'abc',
sellxpath: 'abc',
fromCurrency: 'abc',
toCurrencyXpath: 'abc',
unit: 'M100',
id: 'abc',
};
it('should get receiver currency Xpath', () => {
const detComponent = new BankDetailsComponent(service, bank, fb, dialog);
fixture.whenStable();
fixture.detectChanges();
console.log(detComponent.name); //reads the value of the class variable
const currency: HTMLElement = fixture.debugElement.query(By.css('#toCurrencyXpath')).nativeElement;
fixture.whenStable();
fixture.detectChanges();
expect(currency.textContent).toBe('abc'); //Expected '' to be 'abc'.
});
答案 0 :(得分:0)
让ModelState.IsValid
中的BankDetailsComponent
编译并为您创建它,而不是显式实例化您的TestBed
类。这通常以@angular/core/testing
块的形式完成。
beforeEach
有关更多详细信息,请咨询Component Test Basics。