输入栏为空

我正在表单字段的弹出窗口中加载数据。当我运行它时,输入区域填充有正确的字符串,但是当我尝试对其进行测试时-它为空''。测试期间未使用服务。

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'.

});

hzhdestiny 回答:输入栏为空

ModelState.IsValid中的BankDetailsComponent编译并为您创建它,而不是显式实例化您的TestBed类。这通常以@angular/core/testing块的形式完成。

beforeEach

有关更多详细信息,请咨询Component Test Basics

本文链接:https://www.f2er.com/3167455.html

大家都在问