0

I am trying to write test case for below method but i don't know how to write the test case to cover the code:

getSectionName(sectionId: string) {
    if (sectionId === sectionIds.Homepage) {
      return Section.Homepage;
    } else Iif (sectionId === sectionIds.ProductList) {
      return Section.aboutUs;
    } else {
      return Section.Homepage
    }
}

How to achieve the test case for this method?

James Z
  • 12,209
  • 10
  • 24
  • 44
Angular js
  • 51
  • 9

1 Answers1

0

It could be a test case by calling directly the component function and checking the function result. Acutaly I simplify your function too.

getSectionName(sectionId: string) {
   if (sectionId === sectionIds.ProductList) {
      return Section.aboutUs;
    }
    return Section.Homepage    
}

it(
    "Verify ProductList result",
    waitForAsync(() => {
        const result = component.getSectionName(sectionIds.ProductList);
        expect(result).toBe(Section.aboutUs);       
    })
);
Abel Valdez
  • 2,368
  • 1
  • 16
  • 33