Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup/testing #9

Merged
merged 16 commits into from
Dec 24, 2020
Merged

Setup/testing #9

merged 16 commits into from
Dec 24, 2020

Conversation

matthew-charles-chan
Copy link
Contributor

@matthew-charles-chan matthew-charles-chan commented Dec 23, 2020

Summary

  • Create unit tests for index.js using tap and sinon.
  • Refactor index.js for easier testing.

Test Plan

  • run tests
    $ npm test
    
  • Verify all tests pass

Add createMessage as a method of mail
Refactor sendMail arrow funtion to regular function to have access to the mail object as "this"
sinon
tap
point-of-view
fastify-nodemailer
@matthew-charles-chan matthew-charles-chan changed the title Feat/testing Setup/testing Dec 23, 2020
@matthew-charles-chan matthew-charles-chan linked an issue Dec 23, 2020 that may be closed by this pull request
index.test.js Outdated Show resolved Hide resolved
index.test.js Show resolved Hide resolved
index.test.js Outdated Show resolved Hide resolved
index.test.js Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
fastify.nodemailer.sendMail = sinon.stub().returnsArg(0)
const queued = await fastify.mail.sendMail(testContext)
const { html } = queued
t.error(sinon.assert.calledOnce(fastify.nodemailer.sendMail), 'nodemailer.sendMail is called')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a calledOnceWithExactly that we could use here as well.

https://sinonjs.org/releases/latest/assertions/

Not a requested change, but just an fyi

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know, thanks!

Copy link
Contributor

@jkirkpatrick24 jkirkpatrick24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff, LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add tests
2 participants