Thanks for creating this!
I'm familiar with this technique in sinon, and I find that verifying arguments at the call site often results in better tests than verifying them after execution.
In trying to replicate the patterns I've used in sinon, it wasn't clear from the README how to write the default failing function that handles the wrong-args case.
I include my implementation below in hopes that you include it or something similar in your README:
// A default implementation that fails
const wrongArgs = (...args: any[]) => {
throw new Error(`Wrong args: ${JSON.stringify(args, null, 2)}`);
};
when(fn)
.mockImplementation(wrongArgs)
.calledWith(correctArgs)
.mockReturnValue(expectedValue);
Thanks for creating this!
I'm familiar with this technique in sinon, and I find that verifying arguments at the call site often results in better tests than verifying them after execution.
In trying to replicate the patterns I've used in sinon, it wasn't clear from the README how to write the default failing function that handles the wrong-args case.
I include my implementation below in hopes that you include it or something similar in your README: