Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Created September 3, 2022 18:49
Show Gist options
  • Save trikitrok/d6a9fdeca0d482c86e051544b5f5d501 to your computer and use it in GitHub Desktop.
Save trikitrok/d6a9fdeca0d482c86e051544b5f5d501 to your computer and use it in GitHub Desktop.
import {when} from "jest-when";
export function stub(paymentsRepository) {
const monthPaymentsBuilder = {
inMonth: inMonth
};
return knowingThat;
function knowingThat() {
return monthPaymentsBuilder;
}
function inMonth(month) {
return {
userWith: (userId) => {
return {
hasPaid: (payments) => {
when(paymentsRepository.find).calledWith(userId, month)
.mockReturnValue(payments);
return {
andThat: knowingThat
};
}
};
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment