From 20427b9b92f158dc89c2476b8fbb94a23d2dd848 Mon Sep 17 00:00:00 2001 From: Playwright Service <89237858+playwrightmachine@users.noreply.github.com> Date: Tue, 7 Mar 2023 09:18:44 -0800 Subject: [PATCH] cherry-pick(#21454): fix(types): accept string in expect().toMatch() (#21464) This PR cherry-picks the following commits: - c9eac69f2bfb1dfbbb57d4882ad068374e3a292d Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> --- docs/src/api/class-genericassertions.md | 2 +- packages/playwright-test/types/test.d.ts | 2 +- tests/playwright-test/expect.spec.ts | 1 + utils/generate_types/overrides-test.d.ts | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/src/api/class-genericassertions.md b/docs/src/api/class-genericassertions.md index 575c46e58b..0c67f11b95 100644 --- a/docs/src/api/class-genericassertions.md +++ b/docs/src/api/class-genericassertions.md @@ -418,7 +418,7 @@ expect(value).toMatches(/Is \d+ enough/); ### param: GenericAssertions.toMatch.expected * since: v1.9 -- `expected` <[RegExp]> +- `expected` <[RegExp]|[string]> Regular expression to match against. diff --git a/packages/playwright-test/types/test.d.ts b/packages/playwright-test/types/test.d.ts index acf01877ba..8db789cbf5 100644 --- a/packages/playwright-test/types/test.d.ts +++ b/packages/playwright-test/types/test.d.ts @@ -4095,7 +4095,7 @@ interface GenericAssertions { * * @param expected Regular expression to match against. */ - toMatch(expected: RegExp): R; + toMatch(expected: RegExp | string): R; /** * Compares contents of the value with contents of `expected`, performing "deep equality" check. Allows extra * properties to be present in the value, unlike diff --git a/tests/playwright-test/expect.spec.ts b/tests/playwright-test/expect.spec.ts index 52af2e462c..34c2aec8c8 100644 --- a/tests/playwright-test/expect.spec.ts +++ b/tests/playwright-test/expect.spec.ts @@ -157,6 +157,7 @@ test('should work with generic matchers', async ({ runTSC }) => { expect({}).toEqual({}); expect([1, 2]).toHaveLength(2); expect('abc').toMatch(/a.?c/); + expect('abc').toMatch('abc'); expect({ a: 1, b: 2 }).toMatchObject({ a: 1 }); expect({}).toStrictEqual({}); expect(() => { throw new Error('Something bad'); }).toThrow('something'); diff --git a/utils/generate_types/overrides-test.d.ts b/utils/generate_types/overrides-test.d.ts index 9451e00393..cd15fa00da 100644 --- a/utils/generate_types/overrides-test.d.ts +++ b/utils/generate_types/overrides-test.d.ts @@ -297,7 +297,7 @@ interface GenericAssertions { toEqual(expected: unknown): R; toHaveLength(expected: number): R; toHaveProperty(keyPath: string | Array, value?: unknown): R; - toMatch(expected: RegExp): R; + toMatch(expected: RegExp | string): R; toMatchObject(expected: Record | Array): R; toStrictEqual(expected: unknown): R; toThrow(error?: unknown): R;