Skip to content

Trapping emails sent inside event listeners with Japa #3732

Answered by thetutlage
khawarizmus asked this question in Help
Discussion options

You must be logged in to vote

Focusing on the following code block.

test('Verify Email', async ({ client }, done) => {
    const mailer = Mail.fake()
    Event.emit('user::created', testUser)
      // check if email is sent
      await assert.isTrue(
        mailer.exists((mail) => {
          console.log(mail)
          done()
          return mail.subject === '[T9r9iba] Verify your email'
        })
      )
  }).waitForDone()

This is expected, because the events are emitted outside of the event loop. Infact, that is the purpose of events. Do not block the current event loop and do the thing in the background.

If you await the Event.emit call, then it will be part of the same event loop. Also, do not use done and wai…

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
5 replies
@khawarizmus
Comment options

@thetutlage
Comment options

@khawarizmus
Comment options

@thetutlage
Comment options

@khawarizmus
Comment options

Answer selected by khawarizmus
Comment options

You must be logged in to vote
1 reply
@khawarizmus
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants