I have a function which transform a string with Uppercase to a string with dash before the uppercase and it makes the string lowercase.
formattedType() {
// Adds a dash before the uppercase and make everything lowercase
const type = this.props.type?.split(/(?=[A-Z])/).join("-").toLowerCase();
return type;
}
describe("formattedType method", () => {
it("should transform the string into lowercase with a dash as seperator", () => {
// given
FormTrack.prototype.props.type= 'testOption';
// when
const actualResult = FormTrack.prototype.formattedFormType();
// then
expect(actualResult).toBe('test-option');
});
});
But I'm getting the error below:
Cannot assign to 'type' because it is a read-only property
How can I mock the props type to cover the function formattedType()