parent
bc30cc795e
commit
8ad47b3b17
30
packages/playwright/types/test.d.ts
vendored
30
packages/playwright/types/test.d.ts
vendored
|
|
@ -31,6 +31,10 @@ export type ReporterDescription = Readonly<
|
||||||
[string] | [string, any]
|
[string] | [string, any]
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
type PartialDeep<T> = {
|
||||||
|
[P in keyof T]?: PartialDeep<T[P]>
|
||||||
|
}
|
||||||
|
|
||||||
type UseOptions<TestArgs, WorkerArgs> = Partial<WorkerArgs> & Partial<TestArgs>;
|
type UseOptions<TestArgs, WorkerArgs> = Partial<WorkerArgs> & Partial<TestArgs>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -6423,6 +6427,32 @@ interface GenericAssertions<R> {
|
||||||
* @param expected Regular expression to match against.
|
* @param expected Regular expression to match against.
|
||||||
*/
|
*/
|
||||||
toMatch(expected: RegExp | string): R;
|
toMatch(expected: RegExp | string): R;
|
||||||
|
/**
|
||||||
|
* Compares contents of the value with contents of
|
||||||
|
* [`expected`](https://playwright.dev/docs/api/class-genericassertions#generic-assertions-to-match-object-option-expected),
|
||||||
|
* performing "deep equality" check. Allows extra properties to be present in the value, unlike
|
||||||
|
* [expect(value).toEqual(expected)](https://playwright.dev/docs/api/class-genericassertions#generic-assertions-to-equal),
|
||||||
|
* so you can check just a subset of object properties.
|
||||||
|
*
|
||||||
|
* When comparing arrays, the number of items must match, and each item is checked recursively.
|
||||||
|
*
|
||||||
|
* **Usage**
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* const value = {
|
||||||
|
* a: 1,
|
||||||
|
* b: 2,
|
||||||
|
* c: true,
|
||||||
|
* };
|
||||||
|
* expect(value).toMatchObject({ a: 1, c: true });
|
||||||
|
* expect(value).toMatchObject({ b: 2, c: true });
|
||||||
|
*
|
||||||
|
* expect([{ a: 1, b: 2 }]).toMatchObject([{ a: 1 }]);
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param expected The expected object value to match against.
|
||||||
|
*/
|
||||||
|
toMatchObject<K extends Record<string, unknown>>(expected: DeepPartial<K> | Array<DeepPartial<K>>): R;
|
||||||
/**
|
/**
|
||||||
* Compares contents of the value with contents of
|
* Compares contents of the value with contents of
|
||||||
* [`expected`](https://playwright.dev/docs/api/class-genericassertions#generic-assertions-to-match-object-option-expected),
|
* [`expected`](https://playwright.dev/docs/api/class-genericassertions#generic-assertions-to-match-object-option-expected),
|
||||||
|
|
|
||||||
|
|
@ -324,3 +324,39 @@ test('config should allow void/empty options', async ({ runTSC }) => {
|
||||||
});
|
});
|
||||||
expect(result.exitCode).toBe(0);
|
expect(result.exitCode).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test.fixme('should check types of overloaded toMatchObject with generic parameter', async ({ runTSC }) => {
|
||||||
|
const result = await runTSC({
|
||||||
|
'playwright.config.ts': `
|
||||||
|
import { defineConfig } from '@playwright/test';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
});
|
||||||
|
`,
|
||||||
|
'a.spec.ts': `
|
||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
test('my test', async () => {
|
||||||
|
const value = { a: 1, b: 'foo', c: { d: 2, e: 'bar' } };
|
||||||
|
|
||||||
|
expect.soft(value).toMatchObject<typeof value>({});
|
||||||
|
expect.soft(value).toMatchObject<typeof value>({ a: 1 });
|
||||||
|
expect.soft(value).toMatchObject<typeof value>({ a: 1, c: { e: 'bar' } });
|
||||||
|
expect.soft([value]).toMatchObject<typeof value>([{ a: 1 }]);
|
||||||
|
expect.soft([value]).toMatchObject<typeof value>([{ a: 1, c: { e: 'bar' } }]);
|
||||||
|
|
||||||
|
// @ts-expect-error
|
||||||
|
expect.soft(value).toMatchObject<typeof value>({ a: 'a' });
|
||||||
|
|
||||||
|
// @ts-expect-error
|
||||||
|
expect.soft(value).toMatchObject<typeof value>({ c: { e: 2 } });
|
||||||
|
|
||||||
|
// @ts-expect-error
|
||||||
|
expect.soft([value]).toMatchObject<typeof value>([{ a: 'a' }]);
|
||||||
|
|
||||||
|
// @ts-expect-error
|
||||||
|
expect.soft([value]).toMatchObject<typeof value>([{ c: { e: 2 } }]);
|
||||||
|
});
|
||||||
|
`
|
||||||
|
});
|
||||||
|
expect(result.exitCode).toBe(0);
|
||||||
|
});
|
||||||
|
|
|
||||||
5
utils/generate_types/overrides-test.d.ts
vendored
5
utils/generate_types/overrides-test.d.ts
vendored
|
|
@ -30,6 +30,10 @@ export type ReporterDescription = Readonly<
|
||||||
[string] | [string, any]
|
[string] | [string, any]
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
type DeepPartial<T> = {
|
||||||
|
[P in keyof T]?: DeepPartial<T[P]>
|
||||||
|
}
|
||||||
|
|
||||||
type UseOptions<TestArgs, WorkerArgs> = Partial<WorkerArgs> & Partial<TestArgs>;
|
type UseOptions<TestArgs, WorkerArgs> = Partial<WorkerArgs> & Partial<TestArgs>;
|
||||||
|
|
||||||
interface TestProject<TestArgs = {}, WorkerArgs = {}> {
|
interface TestProject<TestArgs = {}, WorkerArgs = {}> {
|
||||||
|
|
@ -289,6 +293,7 @@ interface GenericAssertions<R> {
|
||||||
toHaveLength(expected: number): R;
|
toHaveLength(expected: number): R;
|
||||||
toHaveProperty(keyPath: string | Array<string>, value?: unknown): R;
|
toHaveProperty(keyPath: string | Array<string>, value?: unknown): R;
|
||||||
toMatch(expected: RegExp | string): R;
|
toMatch(expected: RegExp | string): R;
|
||||||
|
toMatchObject<K extends Record<string, unknown>>(expected: DeepPartial<K> | Array<DeepPartial<K>>): R;
|
||||||
toMatchObject(expected: Record<string, unknown> | Array<unknown>): R;
|
toMatchObject(expected: Record<string, unknown> | Array<unknown>): R;
|
||||||
toStrictEqual(expected: unknown): R;
|
toStrictEqual(expected: unknown): R;
|
||||||
toThrow(error?: unknown): R;
|
toThrow(error?: unknown): R;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue