Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

412
Views
Angular Unit Testing: TypeError: cannot set properties of null (setting 'innerHtml') (Jasmine/Karma)

TypeError: cannot set properties of null (setting 'innerHtml')

I have created a simple angular service that initializes the inner html of a div tag in the main component of my angular project and is called in multiple components. When I run my tests I get the above karma error. I assume this is because the component is not created in the service.spec.ts file. I have checked and the class is defined in the main html file.

service.ts function:

onCLick(value: string): void {
   document.querySelector('div.class').innerHtml = value;
}

service.spec.ts:

descirbe('ClickedService', () => {
   let service: ClickedService;

   beforeEach(() => {
      TestBed.configureTestingModule({});
      service = TestBed.inject(ClickedService);
   });

   to("#onClick should add to innerHtml", () => {
       service.onClick('test value'); // error is here
   });
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!