Uncaught TypeError: Cannot set properties of null (setting 'innerHtml')
I am facing an issue with my Angular project where I have created a simple service to initialize the inner HTML of a div tag in the main component. This service is being called in multiple components, but when running tests, I encounter the error mentioned above in Karma. Upon investigation, it seems like the component is not getting created in the service.spec.ts file, even though the class is defined in the main HTML file.
Service function:
onClick(value: string): void {
document.querySelector('div.class').innerHtml = value;
}
Service test:
descirbe('ClickedService', () => {
let service: ClickedService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(ClickedService);
});
it("should add value to innerHtml on click", () => {
service.onClick('test value'); // this is where the error occurs
});
});