Hi is to possible to set a mocked property to undefined somehow?
Interface I want to mock:
export interface IEmail {
from: string | undefined;
body: string;
to: string;
}
Code I want to test:
async function sendEmail(emailData: IEmail): Promise<void> {
await this.send({
emailBody: emailData.body,
emailBodyFrom: emailData.from || "default_email@mail.com",
emailTo: emailData.to,
});
}
The test:
import { mock } from 'jest-mock-extended';
it('should send email', async () => {
const options = mock<IEmail>({});
options.from = undefined
options.to = 'jane.doe@gmail.com'
mockemailService.send.mockResolvedValueOnce("");
await emailService.sendEmail(options);
expect(mockemailService.send).toHaveBeenCalledWith({
from: 'default_email@mail.com',
to: 'jane.doe@gmail.com',
});
});
I expect this the send function to have been called with default_email@mail.com
but instead it has been called with a mock function causing the test to fail. How can I forcefully set the property from to undefined?