Unit Test Examples

The testing documentation has an example that looks like this:

const db = require('db').connect();
const mailer = require('mailer');
const Users = require('users');

let users = new Users(db, mailer);

module.exports.saveUser = (event, context, callback) => {
  users.save(event.email, callback);

It is listed as a great way to unit test your lambda function. What I’m looking for is an example of how you would actually mock the users variable. The only way that I’ve come up with so far is to change the file to look like this:

module.exports.users = new Users(db, mailer);

This way I could actually mock this users object in my unit test file. Is there a way to mock this without adding users to exports?

Thanks in advance.