You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm testing an API endpoint for signing up users. I used to send a confirmation email from the controller method and I could assert that it was sent using Mailer.fake().
However, when I moved the email sending in an event handler, it is not being invoked during testing. When I use Event.fake() in the test the event does show up but without faking, it'll never get handled.
// in the controllerclassUsersController{publicasyncsignup({ request, response }: HttpContextContract){// ...awaitEvent.emit('user:signup',user)// ...}}// event handler in /start/events.jsEvent.on('user:signup',async(user: User)=>{constemailConfirmation=awaitEmailConfirmation.createFor(user)awaitnewEmailConfirmationMailer(emailConfirmation).sendLater()})
Everything works fine, when testing manually through the dev server. What am I missing?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I'm testing an API endpoint for signing up users. I used to send a confirmation email from the controller method and I could assert that it was sent using
Mailer.fake()
.However, when I moved the email sending in an event handler, it is not being invoked during testing. When I use
Event.fake()
in the test the event does show up but without faking, it'll never get handled.Everything works fine, when testing manually through the dev server. What am I missing?
Beta Was this translation helpful? Give feedback.
All reactions