From 978cd7d80a372808aa175ca92fa6735bbcba5074 Mon Sep 17 00:00:00 2001 From: Mathias Leppich Date: Sat, 21 Sep 2024 00:11:20 +0200 Subject: [PATCH] fix createExpect to retain asymmetric matchers --- packages/playwright/src/matchers/expect.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/playwright/src/matchers/expect.ts b/packages/playwright/src/matchers/expect.ts index 3a254ae7bf..c3a604521f 100644 --- a/packages/playwright/src/matchers/expect.ts +++ b/packages/playwright/src/matchers/expect.ts @@ -153,6 +153,7 @@ function createExpect(info: ExpectMetaInfo, prefix: string[], customMatchers: Re return (matcher as any).call(newThis, ...args); }; Object.defineProperty(wrappedMatchers[key], 'name', { value: name }); + Object.defineProperty(wrappedMatchers[key], 'qualifiedName', { value: key }); extendedMatchers[name] = wrappedMatchers[key]; } expectLibrary.extend(wrappedMatchers); @@ -176,6 +177,24 @@ function createExpect(info: ExpectMetaInfo, prefix: string[], customMatchers: Re return configure({ _poll: poll })(actual, messageOrOptions) as any; }; } + + if (typeof property === 'string' && typeof customMatchers[property] === 'function' && typeof (customMatchers[property] as any).qualifiedName === 'string') { + const qualifiedName = (customMatchers[property] as any).qualifiedName as string; + return (expectLibrary as any)[qualifiedName]; + } + + if (property === 'not') { + return new Proxy(expectLibrary, { + get: function(target: any, property: string) { + if (typeof property === 'string' && typeof customMatchers[property] === 'function' && typeof (customMatchers[property] as any).qualifiedName === 'string') { + const qualifiedName = (customMatchers[property] as any).qualifiedName as string; + return (expectLibrary as any)['not'][qualifiedName]; + } + return (expectLibrary as any)['not'][property]; + }, + }); + } + return (expectLibrary as any)[property]; }, });