marchaos / jest-mock-extended

Type safe mocking extensions for Jest https://www.npmjs.com/package/jest-mock-extended
MIT License
810 stars 56 forks source link

description field for Custom Matcher should be optional #103

Open blzsaa opened 1 year ago

blzsaa commented 1 year ago

The custom matcher part in read me would throw a compile error if used.

// expectedValue is optional export const myMatcher: MatcherCreator = (expectedValue) => new Matcher((actualValue) => { return (expectedValue === actualValue && actualValue.isSpecial); });


- while currently cunstuctor of Matcher requires string description field as well: 
  -  constructor(readonly asymmetricMatch: MatcherFn<T>, **private readonly description: string**)
marchaos commented 1 year ago

Hmm, when the matcher fails, surely the error is indecipherable without a description though?

blzsaa commented 1 year ago

I am not sure if I understand the question correctly but according to my understanding:

E.g. the following code on both the current master branch and on my PR will print out the default jest failure message for toEqual without mentioning anything about description of the matcher.

const stringMatcher = new Matcher((actualValue) => {
    return (actualValue === "value");
}, "description");
const provider = mock<PartyProvider>();
provider.getSongs.calledWith(stringMatcher).mockReturnValue(['Dance the night away', 'Stayin Alive']);
expect(provider.getSongs('disco party')).toEqual(['Dance the night away', 'Stayin Alive']);

will print out:

Error: expect(received).toEqual(expected) // deep equality

Expected: ["Dance the night away", "Stayin Alive"]
Received: undefined

p.s. I hope I did not misunderstand the question or the production code.