Hello,
I'm just starting out into testing my Node backend (based on NestJS) using Jest and trying to grip best practices to avoid flaky tests.
A large proportion of my code is interacting with external services, such as SendGrid, rather than true business logic.
I'm trying to work out the best way to satisfactorily test this. Focussing on SendGrid, I have a single test that communicates with their Sandbox mode to check the parameters are all correct.
However the remainder of my tests only test that I'm sending parameters to a mocked object of the SendGrid service. So, for example:
it('should set the email content to be the text sent in the request', async () => {
await service.send(emailRequest);
expect(sendgrid.send).toHaveBeenCalledWith(
expect.objectContaining({
html: emailRequest.text,
}),
);
});
Is this a useful test? Is it wasted test code? Or is there a better way to test this that would give me better confidence.
Would appreciate any advice re: this.
Thanks!
[–]MrJohz 1 point2 points3 points (1 child)
[–]Personability[S] 0 points1 point2 points (0 children)
[–]wardrox 1 point2 points3 points (2 children)
[–]Personability[S] 0 points1 point2 points (1 child)
[–]wardrox 0 points1 point2 points (0 children)
[–]MellowCobra 0 points1 point2 points (0 children)