Created
November 26, 2020 09:33
-
-
Save qunabu/f6062e6e45f3d0650278fa51258dc6e9 to your computer and use it in GitHub Desktop.
Test Mocki
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const should = require('should'); | |
const mockery = require('mockery'); | |
const nodemailerMock = require('nodemailer-mock'); | |
describe('Tests that send email', async () { | |
before(async () { | |
mockery.enable({warnOnUnregistered: false}); // Enable mockery to mock objects | |
mockery.registerMock('nodemailer', nodemailerMock) | |
}); | |
afterEach(async () { | |
nodemailerMock.mock.reset(); // Reset the mock back to the defaults after each test | |
}); | |
after(async () { | |
// Remove our mocked nodemailer and disable mockery | |
mockery.deregisterAll(); | |
mockery.disable(); | |
}); | |
it('should send an email using nodemailer-mock', async () { | |
app.sendEmail(); // call a service that uses nodemailer | |
const sentMail = nodemailerMock.mock.getSentMail(); // get the array of emails we sent | |
sentMail.length.should.be.exactly(1);// we should have sent one email | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment