-
Notifications
You must be signed in to change notification settings - Fork 489
ERROR in src/app/hero/hero.component.shallow.spec.ts(7,16): error TS2314: Generic type 'ComponentFixture<T>' requires 1 type argument(s). #6
Copy link
Copy link
Open
Description
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.
My code:
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);
});
});
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels