cherry-pick(#21454): fix(types): accept string in expect().toMatch() (#21464)

This PR cherry-picks the following commits:

- c9eac69f2b

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Playwright Service 2023-03-07 09:18:44 -08:00 committed by GitHub
parent 6155a50190
commit 20427b9b92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 4 additions and 3 deletions

View File

@ -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.

View File

@ -4095,7 +4095,7 @@ interface GenericAssertions<R> {
*
* @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

View File

@ -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');

View File

@ -297,7 +297,7 @@ interface GenericAssertions<R> {
toEqual(expected: unknown): R;
toHaveLength(expected: number): R;
toHaveProperty(keyPath: string | Array<string>, value?: unknown): R;
toMatch(expected: RegExp): R;
toMatch(expected: RegExp | string): R;
toMatchObject(expected: Record<string, unknown> | Array<unknown>): R;
toStrictEqual(expected: unknown): R;
toThrow(error?: unknown): R;