I run into this error following the course at Pluralsight. All tests (11 so far) pass, but this error is thrown in the terminal (webstorm).
This concerns chapter 4, mocking child components.
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {HeroesComponent} from './heroes.component';
import {HeroService} from '../hero.service';
import {Component, EventEmitter, Input, NO_ERRORS_SCHEMA, Output} from '@angular/core';
import {of} from 'rxjs/internal/observable/of';
import {Hero} from '../hero';
import {By} from '@angular/platform-browser';
describe('HeroesComponent', () => {
let fixture: ComponentFixture<HeroesComponent>;
let mockHeroService;
let HEROES;
@Component({
selector: 'app-hero',
template: '<div></div>',
})
class FakeHeroComponent {
@Input() hero: Hero;
// @Output() delete = new EventEmitter();
}
beforeEach(() => {
HEROES = [
{id: 1, name: 'SpiderDude', strength: 8},
{id: 2, name: 'Wonderful Woman', strength: 24},
{id: 3, name: 'SuperDude', strength: 55}
];
mockHeroService = jasmine.createSpyObj(['getHeroes', 'addHero', 'deleteHero']);
TestBed.configureTestingModule({
declarations: [HeroesComponent, FakeHeroComponent],
providers: [
{ provide: HeroService, useValue: mockHeroService }
]
// schemas: [NO_ERRORS_SCHEMA] // ignore child component
});
fixture = TestBed.createComponent(HeroesComponent);
});
it('should set heroes correctly from the service', () => {
mockHeroService.getHeroes.and.returnValue(of(HEROES));
fixture.detectChanges();
expect(fixture.componentInstance.heroes.length).toBe(3);
});
it('should create one li for each hero', () => {
mockHeroService.getHeroes.and.returnValue(of(HEROES));
fixture.detectChanges();
expect(fixture.debugElement.queryAll(By.css('li')).length).toBe(3);
});
});