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

111
Views
Jasmine Testing chained function

I have this base class called UIComponent. I have this call in my code

 const detailPanel = this.getParent() //PopupBody
        .getParent() //IComponent
        .getParent() //TabPanel
        .getParent() //TabContents
        .getParent() //TabListControl
        .getParent() //TabControl
        .getParent() //DetailPanelComposition
        .getParent();//DetailPanel

each of the object returned are different classes that inherits the UIComponent class. I tried converting it to the code below hoping it will be easy to convert to Jasmine Unit-test.

  const inputComment = this.getChild("inputComment");
  const PopupBody = this.getParent();
  const iComponent = PopupBody.getParent();
  const tabPanel = iComponent.getParent();
  const tabContents = tabPanel.getParent();
  const tabListControl = tabContents.getParent();
  const tabControl = tabListControl.getParent();
  const detailPanelComposition = tabControl.getParent();
  const detailPanel = detailPanelComposition.getParent();

My issue is that I'm getting it works on the initial this.getParent() but any succeeding getParent() (chained or unchained calls) calls I got an error.

TypeError: Cannot read properties of null (reading 'getParent')

so the test fails from const iComponent = PopupBody.getParent(); or .getParent() //IComponent. What is the best way to test this? Below is my initial test case

describe("The actionComponent.resetComment function", () => {
      let actionComponent;
      let PopupBody;
      let iComponent;
      let tabPanel;
      let tabContents;
      let tabListControl;
      let tabControl;
      let detailPanelComposition;
      let detailPanel;
      beforeEach(() => {
          actionComponent = new ActionComponent();
          spyOn(actionComponent, "getParent").and.callThrough();
          PopupBody = actionComponent.getParent();
      });


      it("gets the PopupBody parent", () => {
          expect(actionComponent.getParent).toHaveBeenCalled();
      });
  });
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!