Angular2: Supplied Parameters Do Not Match Any Signature Of Call Target, Even Though I Have All The Needed Params
push.component.ts import { Component, OnInit } from '@angular/core'; import {PushResult} from './dto/pushResult'; import {PushRequest} from './dto/pushRequest'; impor
Solution 1:
PushComponent
expects a PushService
instance as parameter
constructor(private pushService:PushService) {
but you don't provide one
new PushComponent(/* parameter value missing */);
If you create an instance yourself with new Xxx()
then Angulars DI is not involved and no dependencies are passed.
Only when Angulars DI itself creates PushComponent
does it resolve and pass dependencies.
import {beforeEachProviders, it, describe, inject} from '@angular/core/testing';
describe('my code', () => {
beforeEachProviders(() => [PushService, PushComponent]);
it('does stuff', inject([PushComponent], (pushComponent) => {
// actual test
});
});
Don't expect to get a component injected. What you get this way is an instance of the components class (without any change detection running, nor lifecycle hooks being called, ...)
If you want a component, then you need to use TestBed
. See also https://github.com/angular/angular/blob/master/CHANGELOG.md
Post a Comment for "Angular2: Supplied Parameters Do Not Match Any Signature Of Call Target, Even Though I Have All The Needed Params"