For example I got this email function that is run every time I update the object to some state. It's asynchronous and in production I don't want to wait for the command of send the email to finish to just continue with the script.
But in the TESTS I really want very much to run the code synchronously so I could check that the email was sent too. Or just that the whole process is done as it should.
so in a lot of places I got code that is in normal state runs async but in the test I want to wait for the while process to complete before I test's its validity.
So I thought about Promises + returns structure. For example writing the same command twice. first with return that is run only in test and the second doesn't return anything because it's not supposed to wait to that promise to finish. It's the same thing with async/await, I have to write the same command twice. The first with await and the second without.
It looks very dirty though... just the same command that is written twice in the same place...
Here is a code that demonstrates the hackiness of the thing:
if (process.env.NODE_ENV == "test")
await MailService.sendEmail();
else
MailService.sendEmail();
So how do you tackle this thing? How to not write the same command twice only for the condition of the await?