From 343c46d2b63d958b2e7c8db680cca84cdf72eee9 Mon Sep 17 00:00:00 2001 From: Giles Roadnight <10414642+Roaders@users.noreply.github.com> Date: Wed, 18 May 2022 08:42:34 +0100 Subject: [PATCH] Handle message function or string returned from matcher --- main/mock/matchers.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main/mock/matchers.ts b/main/mock/matchers.ts index 53a3815..9e39b37 100644 --- a/main/mock/matchers.ts +++ b/main/mock/matchers.ts @@ -56,7 +56,10 @@ function mapToJestCustomMatcher(matcher: ICustomMatcher): jest.CustomMatcher { return (context: IFunctionVerifier, received: any, ...actual: any[]) => { const result = matcher.compare(context, received, ...actual); - return { pass: result.pass, message: () => result.message || 'failed' }; + return { + pass: result.pass, + message: typeof result.message === 'function' ? result.message : () => result.message || 'failed', + }; }; }