diff --git a/src/assertions/expect.ts b/src/assertions/expect.ts index 4909878..ccdd962 100644 --- a/src/assertions/expect.ts +++ b/src/assertions/expect.ts @@ -1,17 +1,17 @@ -import {expect as origExpect} from '@playwright/test'; +import {Locator, expect as origExpect} from '@playwright/test'; import {Displayable} from '../materials/Displayable'; -type ExpectReturnType = ReturnType; +type ExpectReturnType = ReturnType>; type SoftType = typeof origExpect.soft; type ConfigureType = typeof origExpect.configure; type PollType = typeof origExpect.poll; type ExtendType = typeof origExpect.extend; export type ExpectType = { - ( - x: unknown, + ( + x: T, messageOrOptions?: string | {message?: string} - ): ExpectReturnType; + ): ExpectReturnType; // These methods are experimental // See https://playwright.dev/docs/test-assertions#negating-matchers for more detail @@ -21,20 +21,21 @@ export type ExpectType = { extend: ExtendType; }; -export const expect = ((): ExpectType => { - const body = ( - x: unknown, - messageOrOptions?: string | {message?: string} - ): ExpectReturnType => { - return origExpect( - x instanceof Displayable ? x._locator : x, - messageOrOptions - ); - }; - return Object.assign(body, { - soft: origExpect.soft.bind(body), - configure: origExpect.configure.bind(body), - poll: origExpect.poll.bind(body), - extend: origExpect.extend.bind(body), - }); -})(); +const expectBody = ( + x: T, + messageOrOptions?: string | {message?: string} +): ExpectReturnType => { + return origExpect( + x instanceof Displayable ? x._locator : x, + messageOrOptions + ); +}; + +// export const expect = Object.assign(expectBody, { +// soft: origExpect.soft.bind(expectBody), +// configure: origExpect.configure.bind(expectBody), +// poll: origExpect.poll.bind(expectBody), +// extend: origExpect.extend.bind(expectBody), +// }); + +export const expect = expectBody;