I am trying to write a unit test case where it calls a method onclick of a dropdown in my component. While running my testcase it gives me the below error.
error TS2345: Argument of type 'string' is not assignable to parameter of type 'Expected<void>'.
Generator.component.ts
templateChanged(selectedTemplate: any) : void{
let profileName: string = '';
switch (selectedTemplate) {
case '1': { // generic app
profileName = 'generic';
break;
}
case '2': { // spring boot
profileName = 'springboot';
break;
}
default: {
alert('selection not handled');
}
}
this.generatorModel = this.generatorService.getDataModel(profileName);
this.formDisabled = false;
for (var k = 0; k < this.generatorModel.ImageDetails.imageList.length; k++) {
if (this.generatorModel.ImageDetails.imageRepo == this.generatorModel.ImageDetails.imageList[k].value) {
this.imageName = this.generatorModel.ImageDetails.imageList[k].name
}
}
this.templateProfile = profileName;
return (this.templateProfile);
}
Generator.component.spec.ts
import { GeneratorComponent } from "./fm-generator.component";
let templateChanged : GeneratorComponent["templateChanged"];
describe('GeneratorComponent', () => {
let applicationTemplate = "";
beforeEach(() => {
applicationTemplate = "springboot";
});
it('should call templateChanged',() => {
const ChosenApplicationTemplate: void = templateChanged(2);
expect (ChosenApplicationTemplate)
.toBe("springboot");
});
});
I understood I am making some mistake in passing the argument for the templateChanged() Method, but not getting the correct syntax to apss teh argument. Could anyone please help me solve this issue.