Open blzsaa opened 1 year ago
Hmm, when the matcher fails, surely the error is indecipherable without a description though?
I am not sure if I understand the question correctly but according to my understanding:
calledWith
which defines behavior and not asserts them, therefore the matchers cannot really fail.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.
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);
});