Tengo esta clase base llamada UIComponent. Tengo esta llamada en mi código.
const detailPanel = this.getParent() //PopupBody .getParent() //IComponent .getParent() //TabPanel .getParent() //TabContents .getParent() //TabListControl .getParent() //TabControl .getParent() //DetailPanelComposition .getParent();//DetailPanelcada uno de los objetos devueltos son clases diferentes que heredan la clase UIComponent. Intenté convertirlo al siguiente código con la esperanza de que fuera fácil convertirlo a la prueba de unidad Jasmine.
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();Mi problema es que estoy haciendo que funcione en el this.getParent() inicial, pero cualquier llamada getParent() (llamadas encadenadas o no encadenadas) que tenga éxito me da un error.
TypeError: Cannot read properties of null (reading 'getParent')entonces la prueba falla desde const iComponent = PopupBody.getParent(); o .getParent() //IComponent. ¿Cuál es la mejor manera de probar esto? A continuación se muestra mi caso de prueba inicial
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(); }); });