Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

113
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda