Skip to content

Instantly share code, notes, and snippets.

@davidbarral
Created June 14, 2022 07:56
Show Gist options
  • Save davidbarral/27d1f88a9a1f03dd1eb82a341f627afc to your computer and use it in GitHub Desktop.
Save davidbarral/27d1f88a9a1f03dd1eb82a341f627afc to your computer and use it in GitHub Desktop.
DI Pragmatic 3
const mockUpdate = jest.fn();
jest.mock("./repos/user.js", () => () => ({
update: mockUpdate;
}));
jest.beforeEach(() => jest.restoreAllMocks());
const updateUserPreference = require("./use-cases/update-user-preference.js");
it("updates the user preference", () => {
updateUserPreference({ key: "someKey", value: "someValue" });
expect(mockUpdate).toHaveBeenCalledWith(/* the updatedUser */);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment