mardi 20 juin 2017

How to write a test case for input changes in Angular

Hi I am developing an application using Angular and TypeScript.

Following is the template code:

<input type="text" placeholder="Search Results" (input)="searchInput($event)">

and my typescript code regarding searchInput method is :

searchInput(event: Event & { target: HTMLInputElement}) {
   const { value } = event.target;
   this.value = value;
    // calling other method to reset values
  }

I was wondering the how to write input test cases in my spec.ts file.

describe('Component', () => {
  let component: Component;
  let fixture: ComponentFixture<Component>;
  const event = Event; // Is this fine ?
  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [
          AppModule
      ],
      providers: [
      ]
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(Component);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('searchInput() ', () => {
    // how to approach 
  });
});

Please provide a way how I will approach for writing test cases.

Aucun commentaire:

Enregistrer un commentaire