diff --git a/src/app/components/inputtextarea/inputtextarea.spec.ts b/src/app/components/inputtextarea/inputtextarea.spec.ts index b3de182602e..1cb0e249900 100755 --- a/src/app/components/inputtextarea/inputtextarea.spec.ts +++ b/src/app/components/inputtextarea/inputtextarea.spec.ts @@ -38,12 +38,37 @@ describe('InputTextarea', () => { const onResizeSpy = spyOn(component, 'onResize').and.callThrough(); const inputTextEl = fixture.debugElement.query(By.css('textarea')); - inputTextEl.nativeElement.dispatchEvent(new Event('focus')); + inputTextEl.nativeElement.value = 'primeng'; + inputTextEl.nativeElement.dispatchEvent(new Event('input')); + fixture.detectChanges(); + + inputTextEl.nativeElement.value = 'primeng rocks!'; + inputTextEl.nativeElement.dispatchEvent(new Event('input')); + fixture.detectChanges(); + + expect(onResizeSpy).toHaveBeenCalledTimes(2); + }); + + it('should change autoResize and resize scrollheight of textarea', () => { + component.autoResize = true; fixture.detectChanges(); - inputTextEl.nativeElement.dispatchEvent(new Event('blur')); + const onResizeSpy = spyOn(component, 'onResize').and.callThrough(); + const inputTextEl = fixture.debugElement.query(By.css('textarea')); + const initialScrollHeight = inputTextEl.nativeElement.scrollHeight; + + inputTextEl.nativeElement.value = 'primeng'; + inputTextEl.nativeElement.dispatchEvent(new Event('input')); + fixture.detectChanges(); + + expect(inputTextEl.nativeElement.scrollHeight).toBeGreaterThan(initialScrollHeight); + const newScrollHeight = inputTextEl.nativeElement.scrollHeight; + + inputTextEl.nativeElement.value = 'primeng rocks!'; + inputTextEl.nativeElement.dispatchEvent(new Event('input')); fixture.detectChanges(); + expect(inputTextEl.nativeElement.scrollHeight).toBeGreaterThan(newScrollHeight); expect(onResizeSpy).toHaveBeenCalledTimes(2); });