Skip to content

Instantly share code, notes, and snippets.

@ceilfors
Created July 5, 2018 06:18
Show Gist options
  • Save ceilfors/aee161e807dff6ccc5e436693680a3ff to your computer and use it in GitHub Desktop.
Save ceilfors/aee161e807dff6ccc5e436693680a3ff to your computer and use it in GitHub Desktop.
better-dependency-injection-with-laconia
const { handler } = require("./lambda");
let twitterService;
beforeEach(() => {
// Creates a mocked twitterService
twitterService = {
getLatestTweets: jest.fn().mockReturnValue(Promise.resolve())
};
});
it("should get tweets for user 1000", () => {
// Runs your exported handler function with the mocked dependencies
handler.run({ twitterService });
expect(twitterService.getLatestTweets).toBeCalledWith(1000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment