3

I have a component that looks like this:

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-youtube',
  templateUrl: './youtube.component.html',
  styleUrls: ['./youtube.component.css']
})
export class YoutubeComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  } 

}

In my karma, spec, I have the following:

import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { YoutubeComponent } from './youtube.component';

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

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      // providers: [YoutubeComponent],tried this, and it makes no difference
      declarations: [ YoutubeComponent ]
    })
    .compileComponents();
  }));

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

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

The error in the Karma browser that I'm getting looks like:

Error: Illegal state: Could not load the summary for directive YouTubeComponent.

It seems that previous, related questions were solved by adding the line declarations: [ YoutubeComponent ], which I already have. Any other advice?

A reproducible example is available on github:

git clone https://github.com/Atticus29/dataJitsu.git
cd dataJitsu
git checkout modalSO
rm package-lock.json
npm install
npm test
Atticus29
  • 4,190
  • 18
  • 47
  • 84
  • 1
    Have you tried adding the modules to `imports: []`? – Alex Szabo Dec 02 '17 at 06:20
  • @Alex Szabó, I'm afraid I don't know exactly what you mean. – Atticus29 Dec 02 '17 at 06:22
  • I have the same issue, did you manage to solve this? – lewtur Mar 05 '18 at 15:58
  • @lewtur not yet – Atticus29 Mar 05 '18 at 21:05
  • I managed to sort mine. I had a pipe with a dodgy generated spec file, and removing that did the trick. The pipe wasn't referenced at all, the test was even marked with "xit" so it wouldn't run but it still caused the error. See https://stackoverflow.com/questions/49114780/angular-testing-illegal-state-could-not-load-the-summary-for-directive-for-a/49115101#49115101 @Atticus29 – lewtur Mar 06 '18 at 16:48

1 Answers1

1

@Atticus29 usually this error comes up when you have missed to:

  1. declare some related component
  2. add some referenced module in imports

try and check for any referenced components or modules.

Prashanth S
  • 91
  • 1
  • 4