From 5b7db90cb630a02a475992f8fa618f521ab1c386 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Tue, 1 Mar 2022 20:04:34 +0100 Subject: [PATCH] chore: hide unsupported expect methods (#12403) --- .../playwright-test/types/testExpect.d.ts | 73 +++++++++++++++---- 1 file changed, 58 insertions(+), 15 deletions(-) diff --git a/packages/playwright-test/types/testExpect.d.ts b/packages/playwright-test/types/testExpect.d.ts index 7976d69b09..2410984fe4 100644 --- a/packages/playwright-test/types/testExpect.d.ts +++ b/packages/playwright-test/types/testExpect.d.ts @@ -31,19 +31,21 @@ export declare type Expect = { (actual: T, message?: string): MakeMatchers; soft: (actual: T, message?: string) => MakeMatchers; - // Sourced from node_modules/expect/build/types.d.ts - assertions(arg0: number): void; extend(arg0: any): void; - extractExpectedAssertionsErrors: typeof expect['extractExpectedAssertionsErrors']; getState(): expect.MatcherState; - hasAssertions(): void; setState(state: Partial): void; - any(expectedObject: any): AsymmetricMatcher; - anything(): AsymmetricMatcher; arrayContaining(sample: Array): AsymmetricMatcher; objectContaining(sample: Record): AsymmetricMatcher; stringContaining(expected: string): AsymmetricMatcher; stringMatching(expected: string | RegExp): AsymmetricMatcher; + /** + * Removed following methods because they rely on a test-runner integration from Jest which we don't support: + * - assertions() + * - extractExpectedAssertionsErrors() + * – hasAssertions() + * - any() + * - anything() + */ }; type ImageComparatorOptions = { @@ -54,18 +56,59 @@ type ImageComparatorOptions = { type Awaited = T extends PromiseLike ? U : T; -type OverriddenExpectProperties = - 'not' | - 'resolves' | - 'rejects' | - 'toMatchInlineSnapshot' | - 'toThrowErrorMatchingInlineSnapshot' | - 'toMatchSnapshot' | - 'toThrowErrorMatchingSnapshot'; +/** + * Removed methods require the jest.fn() integration from Jest to spy on function calls which we don't support: + * - lastCalledWith() + * - lastReturnedWith() + * - nthCalledWith() + * - nthReturnedWith() + * - toBeCalled() + * - toBeCalledTimes() + * - toBeCalledWith() + * - toHaveBeenCalled() + * - toHaveBeenCalledTimes() + * - toHaveBeenCalledWith() + * - toHaveBeenLastCalledWith() + * - toHaveBeenNthCalledWith() + * - toHaveLastReturnedWith() + * - toHaveNthReturnedWith() + * - toHaveReturned() + * - toHaveReturnedTimes() + * - toHaveReturnedWith() + * - toReturn() + * - toReturnTimes() + * - toReturnWith() + * - toThrowErrorMatchingSnapshot() + * - toThrowErrorMatchingInlineSnapshot() + */ +type SupportedExpectProperties = + 'toBe' | + 'toBeCloseTo' | + 'toBeDefined' | + 'toBeFalsy' | + 'toBeGreaterThan' | + 'toBeGreaterThanOrEqual' | + 'toBeInstanceOf' | + 'toBeLessThan' | + 'toBeLessThanOrEqual' | + 'toBeNaN' | + 'toBeNull' | + 'toBeTruthy' | + 'toBeUndefined' | + 'toContain' | + 'toContainEqual' | + 'toEqual' | + 'toHaveLength' | + 'toHaveProperty' | + 'toMatch' | + 'toMatchObject' | + 'toStrictEqual' | + 'toThrow' | + 'toThrowError' declare global { export namespace PlaywrightTest { - export interface Matchers extends Omit, OverriddenExpectProperties> { + export interface Matchers extends Pick, SupportedExpectProperties> { /** * If you know how to test something, `.not` lets you test its opposite. */