This file contains hidden or 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 updateUserPreference = require("./use-cases/update-user-preference.js"); | |
it("updates the user preference", () => { | |
const mockUpdate = jest.fn(); | |
updateUserPreference({ key: "someKey", value: "someValue", { user: { update: mockUpdate } }); | |
expect(mockUpdate).toHaveBeenCalledWith(/* the updatedUser */); | |
}); |
This file contains hidden or 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 updateUserPreference = require("./use-cases/update-user-preference.js"); | |
updateUserPreference({ key: "someKey", value: "someValue" }) |
This file contains hidden or 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 userRepo = require("./repos/user.js"); | |
const defaultRepositories = () => ({ user: userRepo() }); | |
const updateUserPreference = ({ key, value, repositories = defaultRepositories() }) => { | |
// Do stuff and updade the user. | |
repositories.user.update(updatedUser); | |
} |
This file contains hidden or 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 mockUpdate = jest.fn(); | |
jest.mock("./repos/user.js", () => () => ({ | |
update: mockUpdate; | |
})); | |
jest.beforeEach(() => jest.restoreAllMocks()); | |
const updateUserPreference = require("./use-cases/update-user-preference.js"); |
This file contains hidden or 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 updateUserPreference = require("./use-cases/update-user-preference.js"); | |
updateUserPreference({ key: "someKey", value: "someValue" }); |
This file contains hidden or 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 userRepo = require("./repos/user.js"); | |
const updateUserPreference = ({ key, value }) => { | |
// Do stuff and updade the user. | |
const repo = userRepo(); | |
repo.update(updatedUser); | |
} |
This file contains hidden or 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 updateUserPreference = require("./use-cases/update-user-preference.js"); | |
it("updates the user preference", () => { | |
const mockUpdate = jest.fn(); | |
const mockRepo = { update: mockUpdate }; | |
updateUserPreference({ key: "someKey", value: "someValue", { user: mockRepo }); | |
expect(mockUpdate).toHaveBeenCalledWith(/* the updatedUser */); | |
}); |
This file contains hidden or 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 userRepo = require("./repos/user.js"); | |
const updateUserPreference = require("./use-cases/update-user-preference.js"); | |
const user = userRepo(); | |
updateUserPreference({ key: "someKey", value: "someValue", { user }); |
This file contains hidden or 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 updateUserPreference = ({ key, value, repositories }) => { | |
// Do stuff and get an updated user | |
repositories.user.update(updatedUser); | |
} |
This file contains hidden or 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
Promise.cancelable = pendingPromise => { | |
let lazyCb = null; | |
let settled = false; | |
let canceled = false; | |
const promise = Promise.resolve(pendingPromise).then(() => { | |
settled = true; | |
if (canceled) { | |
return; | |
} |
NewerOlder