Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

235
Views
Test case writing for If Else statement

I am writing test case for the conditional if=else statement in angular , test case is not having any error, but when I run the ng test then in code coverage its showing if-else statement is not executed.

Please help me to understand how to write the state case for if-else

bellow is the test case code I wrote ::

  it('Should initialize Edit or View screen based on redirect url', () => {
    const title = 'Edit';
    const titleView = 'View';
    if (title === 'Edit') {
      component.mode = 'Edit';
      expect(component.isEditScreen).toBe(true);
      expect(component.editModeDisabled).toBe(true);
      component.damageForm.controls['address'].disable();
      component.downclaim.disable();
      component.getEditDefaultDropdownValues();
      component.editDamageById(1);
    } else if (titleView === 'View') {
      expect(component.isViewScreen).toBe(true);
      expect(component.viewModeDisabled).toBe(true);
      component.damageForm.disable();
      component.viewDamageById(1);
    }
  });

here is the component. ts file code for same test case

  initEditOrView() {
    this.damageCode = this.route.snapshot.params.id;
    if (this.route.snapshot.data.title === 'Edit') {
      this.mode = 'Edit';
      this.isEditScreen = true;
      this.editModeDisabled = true;
      this.damageForm.controls['address'].disable();
      this.downclaim.disable();
      this.getEditDefaultDropdownValues();
      this.editDamageById(this.damageCode);
    } else if (this.route.snapshot.data.title === 'View') {
      this.isViewScreen = true;
      this.viewModeDisabled = true;
      this.damageForm.disable();
      this.viewDamageById(this.damageCode);
    }
  }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!