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();
});
});