Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(expect): expect.not types (#15487)
Max Schmitt98ea41812495
diff --git a/docs/src/release-notes-csharp.md b/docs/src/release-notes-csharp.mdindex 400b3c0104..5d28afaf0f 100644--- a/docs/src/release-notes-csharp.md+++ b/docs/src/release-notes-csharp.md@@ -327,7 +327,7 @@ Playwright Trace Viewer is now **available online** at https://trace.playwright.-## Ubuntu ARM64 support + more+### Ubuntu ARM64 support + more- Playwright now supports **Ubuntu 20.04 ARM64**. You can now run Playwright tests inside Docker on Apple M1 and on Raspberry Pi.- You can now use Playwright to install stable version of Edge on Linux:diff --git a/packages/playwright-test/types/test.d.ts b/packages/playwright-test/types/test.d.tsindex b231ec13cd..3f61e29531 100644--- a/packages/playwright-test/types/test.d.ts+++ b/packages/playwright-test/types/test.d.ts@@ -3029,6 +3029,23 @@ import type { Suite } from '@playwright/test/types/testReporter';type AsymmetricMatcher = Record<string, any>;+type AsymmetricMatchers = {+ any(sample: unknown): AsymmetricMatcher;+ anything(): AsymmetricMatcher;+ arrayContaining(sample: Array<unknown>): AsymmetricMatcher;+ closeTo(sample: number, precision?: number): AsymmetricMatcher;+ objectContaining(sample: Record<string, unknown>): AsymmetricMatcher;+ stringContaining(sample: string): AsymmetricMatcher;+ stringMatching(sample: string | RegExp): AsymmetricMatcher;+}++type Inverse<Matchers> = {+ /**+ * Inverse next matcher. If you know how to test something, `.not` lets you test its opposite.+ */+ not: Matchers;+};+type IfAny<T, Y, N> = 0 extends (1 & T) ? Y : N;type ExtraMatchers<T, Type, Matchers> = T extends Type ? Matchers : IfAny<T, Matchers, {}>;@@ -3054,6 +3071,16 @@ type MakeMatchers<R, T> = BaseMatchers<R, T> & {ExtraMatchers<T, Locator, LocatorAssertions> &ExtraMatchers<T, APIResponse, APIResponseAssertions>;+type BaseExpect = {+ // Removed following methods because they rely on a test-runner integration from Jest which we don't support:+ // assertions(numberOfAssertions: number): void;+ // extractExpectedAssertionsErrors(): ExpectedAssertionsErrors;+ // hasAssertions(): void;+ extend(matchers: any): void;+ getState(): expectType.MatcherState;+ setState(state: Partial<expectType.MatcherState>): void;+}+export type Expect = {<T = unknown>(actual: T, messageOrOptions?: string | { message?: string }): MakeMatchers<void, T>;soft: <T = unknown>(actual: T, messageOrOptions?: string | { message?: string }) => MakeMatchers<void, T>;@@ -3063,23 +3090,9 @@ export type Expect = {*/not: BaseMatchers<Promise<void>, T>;};-- extend(arg0: any): void;- getState(): expectType.MatcherState;- setState(state: Partial<expectType.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()- */-};+} & BaseExpect &+ AsymmetricMatchers &+ Inverse<Omit<AsymmetricMatchers, 'any' | 'anything'>>;type Awaited<T> = T extends PromiseLike<infer U> ? U : T;diff --git a/tests/playwright-test/expect.spec.ts b/tests/playwright-test/expect.spec.tsindex 4c7051ce88..dd21af5a49 100644--- a/tests/playwright-test/expect.spec.ts+++ b/tests/playwright-test/expect.spec.ts@@ -114,6 +114,7 @@ test('should work with default expect prototype functions', async ({ runTSC, run);expect('foo').toEqual(expect.any(String));expect('foo').toEqual(expect.anything());+ expect('hello world').toEqual(expect.not.stringContaining('text'));});`;{diff --git a/utils/generate_types/index.js b/utils/generate_types/index.jsindex 2211f04753..a0219a5283 100644--- a/utils/generate_types/index.js+++ b/utils/generate_types/index.js@@ -99,7 +99,6 @@ class TypesGenerator {return this.writeComment(docClass.comment) + '\n';}, (className, methodName, overloadIndex) => {if (className === 'SuiteFunction' && methodName === '__call') {- console.log(className, methodName, overloadIndex);const cls = this.documentation.classes.get('Test');const method = cls.membersArray.find(m => m.alias === 'describe' && m.overloadIndex === overloadIndex);return this.memberJSDOC(method, ' ').trimLeft();diff --git a/utils/generate_types/overrides-test.d.ts b/utils/generate_types/overrides-test.d.tsindex 44c584ecd3..ca0bb5f9ca 100644--- a/utils/generate_types/overrides-test.d.ts+++ b/utils/generate_types/overrides-test.d.ts@@ -256,6 +256,23 @@ import type { Suite } from '@playwright/test/types/testReporter';type AsymmetricMatcher = Record<string, any>;+type AsymmetricMatchers = {+ any(sample: unknown): AsymmetricMatcher;+ anything(): AsymmetricMatcher;+ arrayContaining(sample: Array<unknown>): AsymmetricMatcher;+ closeTo(sample: number, precision?: number): AsymmetricMatcher;+ objectContaining(sample: Record<string, unknown>): AsymmetricMatcher;+ stringContaining(sample: string): AsymmetricMatcher;+ stringMatching(sample: string | RegExp): AsymmetricMatcher;+}++type Inverse<Matchers> = {+ /**+ * Inverse next matcher. If you know how to test something, `.not` lets you test its opposite.+ */+ not: Matchers;+};+type IfAny<T, Y, N> = 0 extends (1 & T) ? Y : N;type ExtraMatchers<T, Type, Matchers> = T extends Type ? Matchers : IfAny<T, Matchers, {}>;@@ -281,6 +298,16 @@ type MakeMatchers<R, T> = BaseMatchers<R, T> & {ExtraMatchers<T, Locator, LocatorAssertions> &ExtraMatchers<T, APIResponse, APIResponseAssertions>;+type BaseExpect = {+ // Removed following methods because they rely on a test-runner integration from Jest which we don't support:+ // assertions(numberOfAssertions: number): void;+ // extractExpectedAssertionsErrors(): ExpectedAssertionsErrors;+ // hasAssertions(): void;+ extend(matchers: any): void;+ getState(): expectType.MatcherState;+ setState(state: Partial<expectType.MatcherState>): void;+}+export type Expect = {<T = unknown>(actual: T, messageOrOptions?: string | { message?: string }): MakeMatchers<void, T>;soft: <T = unknown>(actual: T, messageOrOptions?: string | { message?: string }) => MakeMatchers<void, T>;@@ -290,23 +317,9 @@ export type Expect = {*/not: BaseMatchers<Promise<void>, T>;};-- extend(arg0: any): void;- getState(): expectType.MatcherState;- setState(state: Partial<expectType.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()- */-};+} & BaseExpect &+ AsymmetricMatchers &+ Inverse<Omit<AsymmetricMatchers, 'any' | 'anything'>>;type Awaited<T> = T extends PromiseLike<infer U> ? U : T;