Mocking email function in nodejs

前端 未结 4 1871
我寻月下人不归
我寻月下人不归 2021-02-05 09:29

I\'ve got a mailer function I\'ve built and trying to shore up the coverage. Trying to test parts of it have proven tricky, specifically this mailer.smtpTransport.sendMail

4条回答
  •  日久生厌
    2021-02-05 09:54

    expectEmail simply hooks into the transport layer, and expects you to identify the email ( return true if this is the email you are expecting ) by looking at the sentEmail contents.

    In this case, return sentEmail.to === 'dave@testco.com' should suffice.

    Keep in mind however, this module was designed in an environment where tests are ran in a random order and concurrently. You should propably randomize your data heavily to prevent collisions and false positives. BTW we use something like: var to = Date.now().toString(36) + Faker.Internet.email();

提交回复
热议问题