{"_id":"@eclass/nodemailer-mock","_rev":"8-ed7198240a133cc685f37bac6a2e6254","name":"@eclass/nodemailer-mock","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@eclass/nodemailer-mock","version":"1.0.0","keywords":["nodemailer","transport","unit test","test","mock","stub"],"author":{"url":"https://about.me/lgatica","name":"Leonardo Gatica","email":"lgatica@protonmail.com"},"license":"MIT","_id":"@eclass/nodemailer-mock@1.0.0","maintainers":[{"name":"lgatica","email":"lgatica@protonmail.com"}],"homepage":"https://github.com/eclass/nodemailer-mock#readme","bugs":{"url":"https://github.com/eclass/nodemailer-mock/issues"},"dist":{"shasum":"3f1b08485763d9accf2680ccfff5a1449a740df8","tarball":"https://registry.npmjs.org/@eclass/nodemailer-mock/-/nodemailer-mock-1.0.0.tgz","fileCount":19,"integrity":"sha512-5CklxJIn8CrPD790RavQ44Lvn+CaJQY81Es8FVLMsBT9mjgCr1bOdZ6giUOMxkLjHSoUHuUVO4KI/ujI5KNg0g==","signatures":[{"sig":"MEUCIBx0w8xjPPwa0lovlwwhr55fL86lk90uF95gyuTCZR8bAiEAjNN/9MZkrO3uDSVcUWh3XB3XyCjm65KTH+xFBBys/Vc=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":229289,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbkA9ACRA9TVsSAnZWagAA/PIQAIe5F8YhdwMkO8/6EoXN\nHK24BcOyKd8V0LVdbS9Rlg+IkqX0qet9Ip9tXkBXM7vxhGpuWuqpChqVFi9+\nV7aHw5+rIen8lACVuYQZ+oelxXLVfj5BMNibzyuDKk75btxhO85x0kNN1c1v\nGhY0HGzv0FE87Xlr9ZrHfm2gz+ZgujnkWdeoIcisx4AyxPOkixz7q/PUmaqJ\n/fhAAeToxb7Zd54Uc+W9cO3cunwHJvov6ngOR7W2O9/keJY1Wbeke5u/hsOb\nfPiy+0gK/OiwUiIGeSduj+e3eTYyP+4GWFhQsyLaAyTZ/EgtRFvLYqxlLtT1\nrkkoAPl5ysNU0a55hJjsj3kgUa+/YSmLbX1T3MULnc3C1vvhZSZLpQdpw/6Q\nxFQiXCle7vgSNov/h7eEBDuN7UJJOEOD5AGnwagQtfqbNimbZC1mtsyhjpKq\n+lJSWlSw/xZu+B73DDfpQ6Fb4DeNrcLt9dUnDM5CqPqXPQ0eNxmgCKDjNeDB\n85mfTxtj1+KE5iljbN1izOSvUVU2YzLu9ZQxxYdhzPspX6TBftlkp040Cmpj\nk/joTcfLYJ/Qn1UG8UBnQswoZNVw0ilWsJ4K9GnIBjWG+wfrIbouJb+aRizy\nWwaHL4dw1/i3P+3PEW95+0XtjICpfTqD2rKkR7kE+1cxjDUJuhUC4zmkluxj\ngAOH\r\n=QkfO\r\n-----END PGP SIGNATURE-----\r\n"},"main":"nodemailer-mock.js","gitHead":"6eb0b46dafb57f6a7ae67b469389439a96f87345","release":{"fail":false,"prepare":["@semantic-release/changelog","@semantic-release/npm","@semantic-release/git"],"publish":["@semantic-release/npm","@semantic-release/github"],"success":false,"verifyConditions":["@semantic-release/changelog","@semantic-release/npm","@semantic-release/git","@semantic-release/github"]},"scripts":{"lint":"eslint .","sloc":"sloc *.js lib test","test":"mocha --exit","freeze":"rm npm-shrinkwrap.json &2> /dev/null && yarn install && npm prune && npm shrinkwrap","inspect":"NODE_ENV=test ./node_modules/.bin/mocha -s 0 --inspect --debug-brk","coverage":"npm run coverage-report && open ./coverage/lcov-report/index.html","depcheck":"./test/bin/dependency-checker","sloc-app":"sloc *.js lib","validate":"./test/bin/module-validator","sloc-test":"sloc test","coverage-badge":"istanbul-cobertura-badger -e 95 -g 85 -b \"${PWD##*/}\"","coverage-report":"./test/bin/istanbul-coverage-report","semantic-release":"semantic-release","travis-deploy-once":"travis-deploy-once"},"_npmUser":{"name":"lgatica","email":"lgatica@protonmail.com"},"pre-push":[],"pre-commit":["lint","validate","depcheck"],"repository":{"url":"git+https://github.com/eclass/nodemailer-mock.git","type":"git"},"_npmVersion":"6.1.0","description":"Mock nodemailer module for testing","directories":{"lib":"./lib","test":"./test"},"_nodeVersion":"10.6.0","dependencies":{"debug":"3.1.0","nodemailer":"4.4.2"},"_hasShrinkwrap":false,"devDependencies":{"sloc":"0.2.0","mocha":"5.0.0","colors":"1.1.2","eslint":"4.16.0","should":"13.2.1","depcheck":"0.6.8","istanbul":"0.4.5","spec-xunit-file":"0.0.1-3","semantic-release":"15.9.12","travis-deploy-once":"5.0.7","eslint-plugin-mocha":"4.11.0","eslint-config-google":"0.9.1","@semantic-release/git":"7.0.3","@semantic-release/npm":"5.0.4","@semantic-release/github":"5.0.4","istanbul-cobertura-badger":"1.3.1","@semantic-release/changelog":"3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/nodemailer-mock_1.0.0_1536167742813_0.3998182643823698","host":"s3://npm-registry-packages"}}},"time":{"created":"2018-09-05T17:15:42.712Z","modified":"2026-01-12T20:34:15.989Z","1.0.0":"2018-09-05T17:15:43.449Z"},"bugs":{"url":"https://github.com/eclass/nodemailer-mock/issues"},"author":{"url":"https://about.me/lgatica","name":"Leonardo Gatica","email":"lgatica@protonmail.com"},"license":"MIT","homepage":"https://github.com/eclass/nodemailer-mock#readme","keywords":["nodemailer","transport","unit test","test","mock","stub"],"repository":{"url":"git+https://github.com/eclass/nodemailer-mock.git","type":"git"},"description":"Mock nodemailer module for testing","maintainers":[{"email":"lgatica@protonmail.com","name":"lgatica"},{"email":"sgonzalez@eclass.cl","name":"eclass-bot"},{"email":"sebastian@gonzalezr.cl","name":"segonzalezr"}],"readme":"# @eclass/nodemailer-mock\n\n[![nodemailer-mock](https://img.shields.io/npm/v/@eclass/nodemailer-mock.svg)](https://www.npmjs.com/package/@eclass/nodemailer-mock)\n[![Build Status](https://img.shields.io/travis/eclass/nodemailer-mock.svg)](https://travis-ci.org/eclass/nodemailer-mock)\n[![Coverage Status](https://img.shields.io/coveralls/eclass/nodemailer-mock/master.svg?style=flat-square)](https://coveralls.io/github/eclass/nodemailer-mock?branch=master)\n[![Dependency Status](https://david-dm.org/eclass/nodemailer-mock.svg)](https://david-dm.org/eclass/nodemailer-mock)\n[![Dev Dependency Status](https://david-dm.org/eclass/nodemailer-mock/dev-status.svg)](https://david-dm.org/eclass/nodemailer-mock?type=dev)\n[![npm downloads](https://img.shields.io/npm/dm/@eclass/nodemailer-mock.svg)](https://www.npmjs.com/package/@eclass/nodemailer-mock)\n\nMocked nodemailer module for unit testing.\n\n# install\n\n\n```\nnpm install @eclass/nodemailer-mock --save-dev\n```\n\n```\nyarn add -D @eclass/nodemailer-mock\n```\n\n# mock api\nThere are some special methods available on the mocked module to help with testing.\n\n* `nodemailerMock.mock.reset()`\n  * resets the mock class to default values\n* `nodemailerMock.mock.sentMail()`\n  * returns an array of sent emails\n* `nodemailerMock.mock.shouldFailOnce()`\n  * will return an error on the next call to `transport.sendMail()`\n* `nodemailerMock.mock.shouldFail(true|false)`\n  * indicate if errors should be returned for subsequent calls to `transport.sendMail()`\n    * if `true`, return error\n    * if `false`, return success\n* `nodemailerMock.mock.mockedVerify(true|false)`\n  * determine if a call to `transport.verify()` should be mocked or passed through to `nodemailer`\n    * if `true`, use a mocked callback\n    * if `false`, pass through to a real `nodemailer` transport\n* `nodemailerMock.mock.successResponse(success)`\n  * set the success message that is returned in the callback for `transport.sendMail()`\n* `nodemailerMock.mock.failResponse(err)`\n  * set the err that is returned in the callback for `transport.sendMail()`\n\n# usage\nThe mocked module behaves in a similar fashion to other transports provided by `nodemailer`.\n\n```\nconst nodemailerMock = require('@eclass/nodemailer-mock');\nconst transport = nodemailerMock.createTransport();\n\n// the email you want to send\nconst email = ... // <-- your email here\n\n// send an email with nodestyle callback\ntransport.sendMail(email, function(err, info) {\n  if (err) {\n    console.log('Error!', err, info);\n  } else {\n    console.log('Success!', info);\n  }\n}\n\n// send an email with promises\ntransport.sendMail(email)\n.then(function(info) {\n  console.log('Success!', info);\n})\n.catch(function(err) {\n  console.log('Error!', err);\n});\n\n// verify a transport\ntransport.verify(function(err, success) {\n  if (err) {\n    console.log('Error!', err);\n  } else {\n    console.log('Success!', success);\n  }\n})\n```\n\n# example using mocha and mockery\nHere is an example of using a mocked `nodemailer` class in a `mocha` test using `mockery`. Make sure that\nany modules that `require()`'s a mocked module must be called AFTER the module is mocked or node will use\nthe unmocked version from the module cache.\n\n```\nconst should = require('should');\nconst mockery = require('mockery');\nconst nodemailerMock = require('@eclass/nodemailer-mock');\n\ndescribe('Tests that send email', function() {\n\n  /* This could be an app, Express, etc. It should be \n  instantiated *after* nodemailer is mocked. */\n  let app = null;\n\n  before(function() {\n    // Enable mockery to mock objects\n    mockery.enable({\n      warnOnUnregistered: false,\n    });\n    \n    /* Once mocked, any code that calls require('nodemailer') \n    will get our nodemailerMock */\n    mockery.registerMock('nodemailer', nodemailerMock)\n    \n    /*\n    ##################\n    ### IMPORTANT! ###\n    ##################\n    */\n    /* Make sure anything that uses nodemailer is loaded here, \n    after it is mocked just above... */\n\n  });\n  \n  afterEach(function() {\n    // Reset the mock back to the defaults after each test\n    nodemailerMock.mock.reset();\n  });\n  \n  after(function() {\n    // Remove our mocked nodemailer and disable mockery\n    mockery.deregisterAll();\n    mockery.disable();\n  });\n  \n  it('should send an email using nodemailer-mock', function(done) {\n    // call a service that uses nodemailer\n    var response = ... // <-- your email code here\n    \n    // a fake test for something on our response\n    response.value.should.be.exactly('value');\n    \n    // get the array of emails we sent\n    const sentMail = nodemailerMock.mock.sentMail();\n    \n    // we should have sent one email\n    sentMail.length.should.be.exactly(1);\n    \n    // check the email for something\n    sentMail[0].property.should.be.exactly('foobar');\n    \n    done();\n  });\n  \n  it('should fail to send an email using nodemailer-mock', function(done) {\n    // tell the mock class to return an error\n    const err = 'My custom error';\n    nodemailerMock.mock.shouldFailOnce();\n    nodemailerMock.mock.failResponse(err);\n  \n    // call a service that uses nodemailer\n    var response = ... // <-- your code here\n    \n    // a fake test for something on our response\n    response.error.should.be.exactly(err);\n    \n    done();\n  });\n  \n  it('should verify using the real nodemailer transport', function(done) {\n    // tell the mock class to pass verify requests to nodemailer\n    nodemailerMock.mock.mockedVerify(false);\n  \n    // call a service that uses nodemailer\n    var response = ... // <-- your code here\n    \n    /* calls to transport.verify() will be passed through, \n       transport.sendMail() is still mocked */\n\n    done();\n  });\n});\n```\n","readmeFilename":"README.md"}