I am attempting to test my function that takes the value of an input element and assigns it to local variable, however I keep receiving type error:
Cannot read property 'nativeElement' of undefined
Please see my stackblitz for live example
html
<input #timeInput type="text" [value]="myData">
<button (click)="doSomething()">Click</button>
ts
myData = 'initial text';
@ViewChild('timeInput') tI: any;
doSomething() {
this.myData = this.tI.nativeElement.value;
}
test
it('should', () => {
component.something.nativeElement.value = 'new data';
component.myFunc();
expect(component.myData).toEqual('new data');
})