diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.ts index 26738c33e06f6..abbf6f03ab953 100644 --- a/packages/playwright/types/test.d.ts +++ b/packages/playwright/types/test.d.ts @@ -5072,12 +5072,12 @@ type FunctionAssertions = { }; type BaseMatchers = GenericAssertions & PlaywrightTest.Matchers & SnapshotAssertions; -type AllowedGenericMatchers = Pick, 'toBe' | 'toBeDefined' | 'toBeFalsy' | 'toBeNull' | 'toBeTruthy' | 'toBeUndefined'>; +type AllowedGenericMatchers = PlaywrightTest.Matchers & Pick, 'toBe' | 'toBeDefined' | 'toBeFalsy' | 'toBeNull' | 'toBeTruthy' | 'toBeUndefined'>; type SpecificMatchers = - T extends Page ? PageAssertions & AllowedGenericMatchers : - T extends Locator ? LocatorAssertions & AllowedGenericMatchers : - T extends APIResponse ? APIResponseAssertions & AllowedGenericMatchers : + T extends Page ? PageAssertions & AllowedGenericMatchers : + T extends Locator ? LocatorAssertions & AllowedGenericMatchers : + T extends APIResponse ? APIResponseAssertions & AllowedGenericMatchers : BaseMatchers & (T extends Function ? FunctionAssertions : {}); type AllMatchers = PageAssertions & LocatorAssertions & APIResponseAssertions & FunctionAssertions & BaseMatchers; diff --git a/tests/playwright-test/expect.spec.ts b/tests/playwright-test/expect.spec.ts index 2afffb1ac240a..04f69286354fd 100644 --- a/tests/playwright-test/expect.spec.ts +++ b/tests/playwright-test/expect.spec.ts @@ -272,11 +272,21 @@ test('should work with custom PlaywrightTest namespace', async ({ runTSC }) => { } `, 'a.spec.ts': ` - import { test, expect } from '@playwright/test'; + import { test, expect, type Page, type APIResponse } from '@playwright/test'; test.expect.extend({ toBeWithinRange() { }, }); + const page = {} as Page; + const locator = page.locator(''); + const apiResponse = {} as APIResponse; + test.expect(page).toBeEmpty(); + test.expect(page).not.toBeEmpty(); + test.expect(locator).toBeEmpty(); + test.expect(locator).not.toBeEmpty(); + test.expect(apiResponse).toBeEmpty(); + test.expect(apiResponse).not.toBeEmpty(); + test.expect('').toBeEmpty(); test.expect('hello').not.toBeEmpty(); test.expect([]).toBeEmpty(); diff --git a/utils/generate_types/overrides-test.d.ts b/utils/generate_types/overrides-test.d.ts index 441a0cccc0969..5df0c147de49a 100644 --- a/utils/generate_types/overrides-test.d.ts +++ b/utils/generate_types/overrides-test.d.ts @@ -330,12 +330,12 @@ type FunctionAssertions = { }; type BaseMatchers = GenericAssertions & PlaywrightTest.Matchers & SnapshotAssertions; -type AllowedGenericMatchers = Pick, 'toBe' | 'toBeDefined' | 'toBeFalsy' | 'toBeNull' | 'toBeTruthy' | 'toBeUndefined'>; +type AllowedGenericMatchers = PlaywrightTest.Matchers & Pick, 'toBe' | 'toBeDefined' | 'toBeFalsy' | 'toBeNull' | 'toBeTruthy' | 'toBeUndefined'>; type SpecificMatchers = - T extends Page ? PageAssertions & AllowedGenericMatchers : - T extends Locator ? LocatorAssertions & AllowedGenericMatchers : - T extends APIResponse ? APIResponseAssertions & AllowedGenericMatchers : + T extends Page ? PageAssertions & AllowedGenericMatchers : + T extends Locator ? LocatorAssertions & AllowedGenericMatchers : + T extends APIResponse ? APIResponseAssertions & AllowedGenericMatchers : BaseMatchers & (T extends Function ? FunctionAssertions : {}); type AllMatchers = PageAssertions & LocatorAssertions & APIResponseAssertions & FunctionAssertions & BaseMatchers;