简体   繁体   中英

Angular Unit Testing : Karma-Jasmine : ('onChange', (changeEvent: MatRadioChange) : Argument of type void is not assignable to parameter of type

Hi was working on one of the tests for a call that I am using to emit the event:

onChange(eventName: MatRadioChange): void {
    this.eventName.emit(eventName.value);
  }

The test for the same is:

describe('onChange', (eventName: MatRadioChange) => {
    it('should emit true to open calendar modal for mobile view', () => {
      spyOn(component.eventName, 'emit');
      component.onChange(eventName.value);
      expect(component.eventName.emit).toHaveBeenCalled();
    });
  });

I keep getting the error:

Argument of type '(changeEvent: MatRadioChange) => void' is not assignable to parameter of type '() => void'.

describe('onChange', (changeEvent: MatRadioChange) => {

Any help will be great

This is a TypeScript issue. The issue is on this line:

component.onChange(eventName.value);

I assume eventName.value is a string and not MatRadioChange .

To get by this, do this:

component.onChange({ value: 'abc' } as any);

The as any casts the object to any type and it should suffice the MatRadioChange type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM