Tiago Matos
Tiago Matos

Reputation: 1706

Angular 2 Supplied parameters do not match any signature of call target (spec.ts)

I am building Angular2 App using Angular2 Cli. I have a notifications.component which has a constructor like this

constructor(private _elRef: ElementRef) {}

When I build (npm start) I get this error

...angular2/tmp/broccoli_type_script_compiler-input_base_path-wKrIZXNv.tmp/0/src/app/notifications/notifications.component.spec.ts (10, 21): Supplied parameters do not match any signature of call target

The file notifications.component.spec.ts generated by angular cli is like this

import { By }           from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { addProviders, async, inject } from '@angular/core/testing';
import { NotificationsComponent } from './notifications.component';

describe('Component: Notifications', () => {
 it('should create an instance', () => {
 let component = new NotificationsComponent();
 expect(component).toBeTruthy();
 });
});

However, if I build without the constructor parameter everything works fine. If I add this parameter after building, everything works fine as well.

What I am missing?

Upvotes: 4

Views: 3746

Answers (2)

debayan chakravarty
debayan chakravarty

Reputation: 115

Hi bro well there is a temp fix to this as i am into the same problem and no one yet cannot explain how and for what this is happening but you can try out go into the notification.component.ts and change constructor to: "constructor(private _elRef:any = ElementRef) { }" reload then change it back to what it was

Upvotes: 0

Bing Lu
Bing Lu

Reputation: 3402

Look at this line let component = new NotificationsComponent();.

You didn't provide an argument when you create a new object for NotificationsComponent while its constructor expects an object of type ElementRef.

That's why you build without the constructor parameter everything works fine.

Upvotes: 1

Related Questions