Skip to content

Default wrongArgs implementation for README #91

@joebowbeer

Description

@joebowbeer

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions