Angular testing: “Illegal state: Could not load the summary for directive” for an empty component

佐手、 提交于 2019-12-06 01:54:04

Try to change your test to:

it('should create', () => {
    fixture.detectChanges();

    fixture.whenStable().then(() => {
        expect(component).toBeTruthy();
    });
});

Fixed it. I had a pipe which had a spec.ts file as follows:

beforeEach(async(() => {
  TestBed.configureTestingModule({
    declarations: [SafeHtmlPipe],
    providers: [DomSanitizer]
  })
  .compileComponents();
}));

describe('SafeHtmlPipe', () => {
  let pipe;

  beforeEach(() => {
    TestBed.configureTestingModule({
      providers: [DomSanitizer]
    });
  });

  beforeEach(inject([DomSanitizer], p => {
    pipe = p;
  }));

  xit('create an instance', () => {
    expect(pipe).toBeTruthy();
  });
});

Note how the test is turned off with xit. Despite this, and despite that the component under test was not using this pipe, and despite that I imported/declared it in the component anyway, this was causing the issue.

I don't remember writing this, so maybe it was automatically generated, as the pipe it is testing has a DomSanitizer in the constructor.

Removing the file did the trick.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!