Skip to content

Japa Test Mail using trap() function doesn't stop email nor make assertions #3512

Answered by thetutlage
mikesaintsg asked this question in Help
Discussion options

You must be logged in to vote

It because you are trapping the email after making a request to the server.

This is how you are doing it

    await supertest.agent(BASE_URL).get('/').expect(200)

    Mail.trap((message) => {
      assert.deepEqual(message.to, [
        {
          address: 'should fail',
        },
      ])
      assert.deepEqual(message.from, {
        address: 'should fail',
      })
      assert.equal(message.subject, 'should fail')
    })
  })

This is how it should be structured

    // First trap the email
    Mail.trap((message) => {
      assert.deepEqual(message.to, [
        {
          address: 'should fail',
        },
      ])
      assert.deepEqual(message.from, {
        address: 'should fail',

Replies: 1 comment 1 reply

Comment options

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

Answer selected by mikesaintsg
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