3

I am currently using Angular 11. When I run the unit tests, all pass except one which says:

Error: It looks like 'ResultsService' has not been IVY compiled - it has no 'ɵcmp' field

I looked on the forums to see if anyone ran into this error but couldn't find any. Our company recently set up the Ivy Compiler to run as we've upgraded Angular in the past and it looks like it affected one of our unit tests. There's nothing much going on in the ResultsService other than testing if it was created:

import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';

import { ResultsService } from './results.service';

describe('ResultsService', () => {
  let component: ResultsService;
  let fixture: ComponentFixture<ResultsService>;

  beforeEach(waitForAsync(() => {
    TestBed.configureTestingModule({
      providers: [
        HttpClientTestingModule
      ]
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(ResultsService);
    component = fixture.componentInstance;
    fixture.detectChanges();
  })

  afterEach(() => {
    TestBed.resetTestingModule();
  });

  it('should be created', () => {
    expect(component).toBeTruthy();
  });
});

Any help would be appreciated, thanks!

  • 4
    `ResultsService` is a service, not a component. your test rather looks like a boilerplate for a component test – Andrei May 06 '22 at 18:11
  • thanks, I was too focused on the error that I didn't notice this one had boilerplate code for components – Matias Galante May 09 '22 at 15:38

0 Answers0