Argument of type "emit" is not assignable to parameter of type 'never'

infinite picture infinite · May 24, 2018 · Viewed 9.7k times · Source

I need to test a component in Angular which has only one method and certain @Input and @Output properties-

  updateColumns(eventValue: ManagedColumns) {
    this.applyColumnChanges.emit(eventValue);
  }

There is another component that has method which is supposed to call the above method. Call as in it is emitting an event which will be consumed by the other one I believe which in turn emits another event which is consumed by third one in a different component -

applyChanges() {
        this.apply.emit(<ManagedColumns>{
            selectedColumns: this.selectedItems.slice(),
            availableColumns: this.availableItems.slice()
        });
        this.closeDialog();
    }

I am trying to test the updateColumns but lost up as how to do it? Is it possible to mock the applyChanges which in turns emits to updateColumns and we can check for same values?

If I tried -

manageColumnsComponent = TestBed.createComponent(ManageColumnsComponent).componentInstance;
    spyOn(manageColumnsComponent.applyChanges, 'emit');

Get error -

[ts] Argument of type '"emit"' is not assignable to parameter of type 'never'.

Answer

Robert Maxwell picture Robert Maxwell · Aug 20, 2018

You need to spyOn the actual eventEmitter variable, not the function.

spyOn(manageColumnsComponent.apply, 'emit')