Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: hide unsupported expect methods (#12403)

Max Schmitt5b7db90cb630
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 = {
<T = unknown>(actual: T, message?: string): MakeMatchers<T>;
soft: <T = unknown>(actual: T, message?: string) => MakeMatchers<T>;
- // 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<expect.MatcherState>): void;
- any(expectedObject: any): AsymmetricMatcher;
- anything(): AsymmetricMatcher;
arrayContaining(sample: Array<unknown>): AsymmetricMatcher;
objectContaining(sample: Record<string, unknown>): 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> = T extends PromiseLike<infer U> ? 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<R> extends Omit<expect.Matchers<R>, OverriddenExpectProperties> {
+ export interface Matchers<R> extends Pick<expect.Matchers<R>, SupportedExpectProperties> {
/**
* If you know how to test something, `.not` lets you test its opposite.
*/