Click here to Skip to main content
15,359,191 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello, I have a method called
onShowList()
and I want to write a unit test case for it, I am a beginner with writing a test cases so please help


TypeScript
 public onShowList(): void {
  this.showList = !this.showList;
  if (this.showList) {
    this.calcListPosition();
    this.showListOverlay();

    if (this.searchable) {
      setTimeout(() => {
          this.searchFilter.nativeElement.value = '';
          this.searchFilter.nativeElement.focus()
        }
        , 0);
    }
  }
}


What I have tried:

I have a spec file, and I tried to call this method by writing this code

TypeScript
fdescribe('DropDownComponent', () => {
 let component: DropDownComponent;
 let fixture: ComponentFixture<DropDownComponent>;

 beforeEach(async () => {
   await TestBed.configureTestingModule({
     declarations: [ DropDownComponent ],
     imports: [
        CoreTranslationModule.forRoot(),
        HttpClientTestingModule
     ]
   })
   .compileComponents();
 });

 beforeEach(() => {
   fixture = TestBed.createComponent(DropDownComponent);
   component = fixture.componentInstance;
   fixture.detectChanges();
 });
  it('should create', () => {
   console.log(123456,component.onShowList())
   expect(component.onShowList()).toBe();
 });


what code should I write next to test this component
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900