This spec gives me a
"Error: Can't resolve all parameters for FooComponent: (?)."
error and I can't see why. Any help on this would be appreciated.
import {Component, Host } from '@angular/core';
import {BarComponent} from './bar.component';
@Component({
selector: 'foo',
template: `<div>foo</div>`
})
export class FooComponent {
constructor(@Host() private barComponent: BarComponent) {
// do something with bar
}
}
import {Component, Injectable} from '@angular/core';
@Component({
selector: 'bar',
template: `<div>bar<foo/></div>`
})
@Injectable()
export class BarComponent { }
import {TestBed, async, ComponentFixture} from '@angular/core/testing';
import {FooComponent} from './foo.component';
import {BarComponent} from './bar.component';
describe('FooComponent', () => {
let component: FooComponent;
let fixture: ComponentFixture<FooComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
FooComponent,
],
providers: [
BarComponent
],
});
}));
beforeEach(() => {
fixture = TestBed.createComponent(FooComponent);
component = fixture.componentInstance;
});
it('should compile', () => {
expect(component).toBeTruthy();
});
});
Maybe overrideComponent method of configureTestingModule will help:
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
FooComponent,
]
}).overrideComponent(FooComponent, {
add: {
providers: [
{ provide: BarComponent }
]
}
});
}));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With