lundi 15 janvier 2018

ng-reflect vs. 'real' attribute value on nativeElement during testing

I try to test a custom input element in angular4/5 with karma/jasmine nut I can't figure out if I miss a thing.

Can anybody please point me in the right direction?

So I have a custom input component like:

<div>
  <input class="input-class" [type]="inputType" [required]="required" [disabled]="disabled"          [(ngModel)]="value" (input)="handleChange()" />
  <label>...</label>
</div>

Now I like to test the disabled attribute on the nativeElement for example:

it('can be disabled', () => {
formControl.disable();
    let inputElement = fixture.debugElement.query(By.css('input-element'))
    fixture.detectChanges();
    // works:
    expect(inputElement.attributes.getNamedItem('ng-reflect-is-disabled')).toBeTruthy();
    // works not:
    expect(inputElement.disabled).toBeTruthy();   
    // also doesn't work:
    expect(inputElement.attributes.getNamedItem('disabled')).toBeTruthy();
  });

Why can I see the change on the ng-reflect attribute but not on the original? Do I miss a call to trigger a lifecyle event? O have I to use protractor test?

Aucun commentaire:

Enregistrer un commentaire