Closed AnthonyIacono closed 4 years ago
Can't say I tried it, but custom matchers seem to be possible. You can look here for how matchers are implemented, you'd need to pass an object with a match property that is a function, taking in a value and returning a boolean.
const cheeseMatcher = {match: (value: any) => value.boop === 'cheese'}
when(something.whatever(cheeseMatcher)).thenResolve('meow')
The cleaner way might probably be to implement the matcher in a class and then expose the matcher method like so:
export function cheeseMatcher(): any {
return new CheeseMatcher() as any;
}
References: Matcher: https://github.com/NagRock/ts-mockito/blob/master/src/matcher/type/AnyNumberMatcher.ts Exposing matcher method: https://github.com/NagRock/ts-mockito/blob/master/src/ts-mockito.ts#L112
Thanks @gCardinal for posting solution.
First of all, thank you so much for this wonderful tool! Is there a way to make a custom matcher?
ie: