parent
8ad47b3b17
commit
4b5435e8e2
26
packages/playwright/types/test.d.ts
vendored
26
packages/playwright/types/test.d.ts
vendored
|
|
@ -31,8 +31,8 @@ export type ReporterDescription = Readonly<
|
|||
[string] | [string, any]
|
||||
>;
|
||||
|
||||
type PartialDeep<T> = {
|
||||
[P in keyof T]?: PartialDeep<T[P]>
|
||||
type DeepPartial<T> = {
|
||||
[P in keyof T]?: DeepPartial<T[P]>
|
||||
}
|
||||
|
||||
type UseOptions<TestArgs, WorkerArgs> = Partial<WorkerArgs> & Partial<TestArgs>;
|
||||
|
|
@ -6479,6 +6479,28 @@ interface GenericAssertions<R> {
|
|||
* @param expected The expected object value to match against.
|
||||
*/
|
||||
toMatchObject(expected: Record<string, unknown> | Array<unknown>): R;
|
||||
/**
|
||||
* Compares contents of the value with contents of
|
||||
* [`expected`](https://playwright.dev/docs/api/class-genericassertions#generic-assertions-to-strict-equal-option-expected)
|
||||
* **and** their types.
|
||||
*
|
||||
* Differences from
|
||||
* [expect(value).toEqual(expected)](https://playwright.dev/docs/api/class-genericassertions#generic-assertions-to-equal):
|
||||
* - Keys with undefined properties are checked. For example, `{ a: undefined, b: 2 }` does not match `{ b: 2 }`.
|
||||
* - Array sparseness is checked. For example, `[, 1]` does not match `[undefined, 1]`.
|
||||
* - Object types are checked to be equal. For example, a class instance with fields `a` and `b` will not equal a
|
||||
* literal object with fields `a` and `b`.
|
||||
*
|
||||
* **Usage**
|
||||
*
|
||||
* ```js
|
||||
* const value = { prop: 1 };
|
||||
* expect(value).toStrictEqual({ prop: 1 });
|
||||
* ```
|
||||
*
|
||||
* @param expected Expected value.
|
||||
*/
|
||||
toStrictEqual<K>(expected: K): R;
|
||||
/**
|
||||
* Compares contents of the value with contents of
|
||||
* [`expected`](https://playwright.dev/docs/api/class-genericassertions#generic-assertions-to-strict-equal-option-expected)
|
||||
|
|
|
|||
|
|
@ -360,3 +360,41 @@ test.fixme('should check types of overloaded toMatchObject with generic paramete
|
|||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
});
|
||||
|
||||
test.fixme('should check types of overloaded toStrictEqual 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).toStrictEqual<typeof value>({ a: 1, b: 'foo', c: { d: 2, e: 'bar' } });
|
||||
expect.soft([value]).toStrictEqual<Array<typeof value>>([{ a: 1, b: 'foo', c: { d: 2, e: 'bar' } }]);
|
||||
|
||||
expect.soft(new Date()).toStrictEqual<Date>(new Date());
|
||||
|
||||
// @ts-expect-error
|
||||
expect.soft(value).toStrictEqual<typeof value>({ a: 1 });
|
||||
|
||||
// @ts-expect-error
|
||||
expect.soft(value).toStrictEqual<typeof value>({ a: 'a' });
|
||||
|
||||
// @ts-expect-error
|
||||
expect.soft(value).toStrictEqual<typeof value>({ c: { e: 2 } });
|
||||
|
||||
// @ts-expect-error
|
||||
expect.soft([value]).toStrictEqual<typeof value>([{ a: 'a' }]);
|
||||
|
||||
// @ts-expect-error
|
||||
expect.soft([value]).toStrictEqual<typeof value>([{ c: { e: 2 } }]);
|
||||
});
|
||||
`
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
});
|
||||
1
utils/generate_types/overrides-test.d.ts
vendored
1
utils/generate_types/overrides-test.d.ts
vendored
|
|
@ -295,6 +295,7 @@ interface GenericAssertions<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;
|
||||
toStrictEqual<K>(expected: K): R;
|
||||
toStrictEqual(expected: unknown): R;
|
||||
toThrow(error?: unknown): R;
|
||||
toThrowError(error?: unknown): R;
|
||||
|
|
|
|||
Loading…
Reference in a new issue