From f2bdeb29ef791878ed84f8e9bc7b8e058266e0f1 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 17 Mar 2022 21:37:46 +0100 Subject: [PATCH] cherry-pick(#12820): chore: restore expect.any()/expect.anything() (#12849) --- .../playwright-test/types/testExpect.d.ts | 4 +-- tests/playwright-test/expect.spec.ts | 28 ++++++++++++++----- .../playwright-test-fixtures.ts | 3 +- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/packages/playwright-test/types/testExpect.d.ts b/packages/playwright-test/types/testExpect.d.ts index 10aa1bba7f..38053a8413 100644 --- a/packages/playwright-test/types/testExpect.d.ts +++ b/packages/playwright-test/types/testExpect.d.ts @@ -34,6 +34,8 @@ export declare type Expect = { extend(arg0: any): void; getState(): expect.MatcherState; setState(state: Partial): void; + any(expectedObject: any): AsymmetricMatcher; + anything(): AsymmetricMatcher; arrayContaining(sample: Array): AsymmetricMatcher; objectContaining(sample: Record): AsymmetricMatcher; stringContaining(expected: string): AsymmetricMatcher; @@ -43,8 +45,6 @@ export declare type Expect = { * - assertions() * - extractExpectedAssertionsErrors() * – hasAssertions() - * - any() - * - anything() */ }; diff --git a/tests/playwright-test/expect.spec.ts b/tests/playwright-test/expect.spec.ts index f91c2c3fc6..bfb81a4634 100644 --- a/tests/playwright-test/expect.spec.ts +++ b/tests/playwright-test/expect.spec.ts @@ -118,17 +118,31 @@ test('should include custom error message with web-first assertions', async ({ r ].join('\n')); }); -test('should work with default expect prototype functions', async ({ runTSC }) => { - const result = await runTSC({ - 'a.spec.ts': ` - const { test } = pwt; +test('should work with default expect prototype functions', async ({ runTSC, runInlineTest }) => { + const spec = ` + const { test } = pwt; + test('pass', async () => { const expected = [1, 2, 3, 4, 5, 6]; test.expect([4, 1, 6, 7, 3, 5, 2, 5, 4, 6]).toEqual( expect.arrayContaining(expected), ); - ` - }); - expect(result.exitCode).toBe(0); + expect('foo').toEqual(expect.any(String)); + expect('foo').toEqual(expect.anything()); + }); + `; + { + const result = await runTSC({ + 'a.spec.ts': spec, + }); + expect(result.exitCode).toBe(0); + } + { + const result = await runInlineTest({ + 'a.spec.ts': spec, + }); + expect(result.exitCode).toBe(0); + expect(result.passed).toBe(1); + } }); test('should work with default expect matchers', async ({ runTSC }) => { diff --git a/tests/playwright-test/playwright-test-fixtures.ts b/tests/playwright-test/playwright-test-fixtures.ts index e0c6dbad76..f18d3641bb 100644 --- a/tests/playwright-test/playwright-test-fixtures.ts +++ b/tests/playwright-test/playwright-test-fixtures.ts @@ -241,7 +241,8 @@ const TSCONFIG = { 'esModuleInterop': true, 'allowSyntheticDefaultImports': true, 'rootDir': '.', - 'lib': ['esnext', 'dom', 'DOM.Iterable'] + 'lib': ['esnext', 'dom', 'DOM.Iterable'], + 'noEmit': true, }, 'exclude': [ 'node_modules'