I have a simple angular2 component as defined below. And I'm looking to create a unit testing with karma, jasmine to run through this component.
@Component({
selector: 'property',
template: require('./property.component.html'),
directives: [Panel],
providers: [ConfigService]});
export class PropertyComponent {
config:any;
constructor(config:ConfigService) {
this.config = config.getConfig();
}
}
This is my testing spec file.
describe('property component', () => {
it('should have property page title', injectAsync([TestComponentBuilder], (tcb) => {
return tcb.createAsync(PropertyComponent).then((fixture) => {
let propertyComp = fixture.componentInstance,
element = fixture.nativeElement;
expect(element.querySelector('h1').innerText).toBe('property page');
});
}));
})
However I got a list of weird errors... I'm guessing this is due to the ConfigService Provider in the PropertyComponent, because when I removed the provider dependency, it went through.
Does anyone know how to deal with the dependency Providers?
Thanks!
errors:
_instantiateProvider@angular2-seed/config/spec-bundle.js:23435:38
_new@angular2-seed/config/spec-bundle.js:23424:42
getObjByKeyId@angular2-seed/config/spec-bundle.js:22937:38
_getByKeyDefault@angular2-seed/config/spec-bundle.js:23641:51
_getByKey@angular2-seed/config/spec-bundle.js:23587:42
_getByDependency@angular2-seed/config/spec-bundle.js:23573:35
_instantiate@angular2-seed/config/spec-bundle.js:23463:53
_instantiateProvider@angular2-seed/config/spec-bundle.js:23435:38
_new@angular2-seed/config/spec-bundle.js:23424:42
instantiateProvider@angular2-seed/config/spec-bundle.js:22924:35
init@angular2-seed/config/spec-bundle.js:34694:44
AppElement@angular2-seed/config/spec-bundle.js:34371:33
viewFactory_HostPropertyComponent0
createRootHostView@angular2-seed/config/spec-bundle.js:35741:48