Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

110
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda