Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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'.
like image 703
infinite Avatar asked Jan 03 '23 08:01

infinite


1 Answers

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

spyOn(manageColumnsComponent.apply, 'emit')
like image 176
Robert Maxwell Avatar answered Jan 17 '23 11:01

Robert Maxwell