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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…