Skip to content

Commit

Permalink
fix broken unit test and add new test
Browse files Browse the repository at this point in the history
  • Loading branch information
RogueTea committed May 17, 2024
1 parent b55baa8 commit 25915e7
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/app/components/inputtextarea/inputtextarea.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { By } from '@angular/platform-browser';
import { InputTextarea } from './inputtextarea';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { Component, DebugElement } from '@angular/core';
import e from 'express';

@Component({
template: `<textarea rows="1" cols="1" (onResize)="onResize($event)" [autoResize]="autoResize" pInputTextarea></textarea> `
Expand All @@ -13,7 +14,7 @@ class TestInputTextArea {
onResize(event) {}
}

describe('InputTextarea', () => {
fdescribe('InputTextarea', () => {
let fixture: ComponentFixture<TestInputTextArea>;
let component: TestInputTextArea;
beforeEach(() => {
Expand All @@ -38,12 +39,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 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);
});

Expand Down

0 comments on commit 25915e7

Please sign in to comment.