lundi 19 septembre 2016

Updating input html field from within an Angular 2 test

I would like to change the value of an input field from within an Angular 2 unit test.

        <input type="text" class="form-control" [(ngModel)]="abc.value" />

I can't just change the ngModel because 'abc' object is private:

 private abc: Abc = new Abc();

In Angular 2 testing, can I simulate the user typing into the input field so that the ngModel will be updated with what the user has typed from within a unit test?

I can grab the DebugElement and the nativeElement of the input field without a problem. (Just setting a the 'value' property on the nativeElement of the input field doesn't seem to work as it doesn't update the ngModel with what I've set for the value).

Maybe 'inputDebugEl.triggerEventHandler' can be called, but I'm not sure what arguments to give it so it will simulate the user having typed a particular string of input.

Thank you very much for your help!

Aucun commentaire:

Enregistrer un commentaire