mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix: expect.poll type with custom matcher (#35651)
This commit is contained in:
parent
2ece112cb3
commit
36a628d902
10
packages/playwright/types/test.d.ts
vendored
10
packages/playwright/types/test.d.ts
vendored
@ -7747,9 +7747,9 @@ type AllMatchers<R, T> = PageAssertions & LocatorAssertions & APIResponseAsserti
|
|||||||
|
|
||||||
type IfAny<T, Y, N> = 0 extends (1 & T) ? Y : N;
|
type IfAny<T, Y, N> = 0 extends (1 & T) ? Y : N;
|
||||||
type Awaited<T> = T extends PromiseLike<infer U> ? U : T;
|
type Awaited<T> = T extends PromiseLike<infer U> ? U : T;
|
||||||
type ToUserMatcher<F> = F extends (first: any, ...args: infer Rest) => infer R ? (...args: Rest) => (R extends PromiseLike<infer U> ? Promise<void> : void) : never;
|
type ToUserMatcher<F, DefaultReturnType> = F extends (first: any, ...args: infer Rest) => infer R ? (...args: Rest) => (R extends PromiseLike<infer U> ? Promise<void> : DefaultReturnType) : never;
|
||||||
type ToUserMatcherObject<T, ArgType> = {
|
type ToUserMatcherObject<T, DefaultReturnType, ArgType> = {
|
||||||
[K in keyof T as T[K] extends (arg: ArgType, ...rest: any[]) => any ? K : never]: ToUserMatcher<T[K]>;
|
[K in keyof T as T[K] extends (arg: ArgType, ...rest: any[]) => any ? K : never]: ToUserMatcher<T[K], DefaultReturnType>;
|
||||||
};
|
};
|
||||||
|
|
||||||
type MatcherHintColor = (arg: string) => string;
|
type MatcherHintColor = (arg: string) => string;
|
||||||
@ -7818,14 +7818,14 @@ type MakeMatchers<R, T, ExtendedMatchers> = {
|
|||||||
* If the promise is fulfilled the assertion fails.
|
* If the promise is fulfilled the assertion fails.
|
||||||
*/
|
*/
|
||||||
rejects: MakeMatchers<Promise<R>, any, ExtendedMatchers>;
|
rejects: MakeMatchers<Promise<R>, any, ExtendedMatchers>;
|
||||||
} & IfAny<T, AllMatchers<R, T>, SpecificMatchers<R, T> & ToUserMatcherObject<ExtendedMatchers, T>>;
|
} & IfAny<T, AllMatchers<R, T>, SpecificMatchers<R, T> & ToUserMatcherObject<ExtendedMatchers, R, T>>;
|
||||||
|
|
||||||
type PollMatchers<R, T, ExtendedMatchers> = {
|
type PollMatchers<R, T, ExtendedMatchers> = {
|
||||||
/**
|
/**
|
||||||
* If you know how to test something, `.not` lets you test its opposite.
|
* If you know how to test something, `.not` lets you test its opposite.
|
||||||
*/
|
*/
|
||||||
not: PollMatchers<R, T, ExtendedMatchers>;
|
not: PollMatchers<R, T, ExtendedMatchers>;
|
||||||
} & BaseMatchers<R, T> & ToUserMatcherObject<ExtendedMatchers, T>;
|
} & BaseMatchers<R, T> & ToUserMatcherObject<ExtendedMatchers, R, T>;
|
||||||
|
|
||||||
export type Expect<ExtendedMatchers = {}> = {
|
export type Expect<ExtendedMatchers = {}> = {
|
||||||
<T = unknown>(actual: T, messageOrOptions?: string | { message?: string }): MakeMatchers<void, T, ExtendedMatchers>;
|
<T = unknown>(actual: T, messageOrOptions?: string | { message?: string }): MakeMatchers<void, T, ExtendedMatchers>;
|
||||||
|
|||||||
@ -220,3 +220,24 @@ test('step.skip returns void ', async ({ runTSC }) => {
|
|||||||
});
|
});
|
||||||
expect(result.exitCode).toBe(0);
|
expect(result.exitCode).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('calling custom matcher on expect.poll should return Promise', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/35635' } }, async ({ runTSC }) => {
|
||||||
|
const result = await runTSC({
|
||||||
|
'a.spec.ts': `
|
||||||
|
import { test, expect as baseExpect } from '@playwright/test';
|
||||||
|
const expect = baseExpect.extend({
|
||||||
|
toBeFoo(actual) {
|
||||||
|
return {
|
||||||
|
pass: actual === 'foo',
|
||||||
|
message: () => 'not foo!',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
test('test', async () => {
|
||||||
|
const pollingPromise: Promise<any> = expect.poll(() => 'foo').toBeFoo();
|
||||||
|
await pollingPromise;
|
||||||
|
});
|
||||||
|
`
|
||||||
|
});
|
||||||
|
expect(result.exitCode).toBe(0);
|
||||||
|
});
|
||||||
|
|||||||
10
utils/generate_types/overrides-test.d.ts
vendored
10
utils/generate_types/overrides-test.d.ts
vendored
@ -367,9 +367,9 @@ type AllMatchers<R, T> = PageAssertions & LocatorAssertions & APIResponseAsserti
|
|||||||
|
|
||||||
type IfAny<T, Y, N> = 0 extends (1 & T) ? Y : N;
|
type IfAny<T, Y, N> = 0 extends (1 & T) ? Y : N;
|
||||||
type Awaited<T> = T extends PromiseLike<infer U> ? U : T;
|
type Awaited<T> = T extends PromiseLike<infer U> ? U : T;
|
||||||
type ToUserMatcher<F> = F extends (first: any, ...args: infer Rest) => infer R ? (...args: Rest) => (R extends PromiseLike<infer U> ? Promise<void> : void) : never;
|
type ToUserMatcher<F, DefaultReturnType> = F extends (first: any, ...args: infer Rest) => infer R ? (...args: Rest) => (R extends PromiseLike<infer U> ? Promise<void> : DefaultReturnType) : never;
|
||||||
type ToUserMatcherObject<T, ArgType> = {
|
type ToUserMatcherObject<T, DefaultReturnType, ArgType> = {
|
||||||
[K in keyof T as T[K] extends (arg: ArgType, ...rest: any[]) => any ? K : never]: ToUserMatcher<T[K]>;
|
[K in keyof T as T[K] extends (arg: ArgType, ...rest: any[]) => any ? K : never]: ToUserMatcher<T[K], DefaultReturnType>;
|
||||||
};
|
};
|
||||||
|
|
||||||
type MatcherHintColor = (arg: string) => string;
|
type MatcherHintColor = (arg: string) => string;
|
||||||
@ -438,14 +438,14 @@ type MakeMatchers<R, T, ExtendedMatchers> = {
|
|||||||
* If the promise is fulfilled the assertion fails.
|
* If the promise is fulfilled the assertion fails.
|
||||||
*/
|
*/
|
||||||
rejects: MakeMatchers<Promise<R>, any, ExtendedMatchers>;
|
rejects: MakeMatchers<Promise<R>, any, ExtendedMatchers>;
|
||||||
} & IfAny<T, AllMatchers<R, T>, SpecificMatchers<R, T> & ToUserMatcherObject<ExtendedMatchers, T>>;
|
} & IfAny<T, AllMatchers<R, T>, SpecificMatchers<R, T> & ToUserMatcherObject<ExtendedMatchers, R, T>>;
|
||||||
|
|
||||||
type PollMatchers<R, T, ExtendedMatchers> = {
|
type PollMatchers<R, T, ExtendedMatchers> = {
|
||||||
/**
|
/**
|
||||||
* If you know how to test something, `.not` lets you test its opposite.
|
* If you know how to test something, `.not` lets you test its opposite.
|
||||||
*/
|
*/
|
||||||
not: PollMatchers<R, T, ExtendedMatchers>;
|
not: PollMatchers<R, T, ExtendedMatchers>;
|
||||||
} & BaseMatchers<R, T> & ToUserMatcherObject<ExtendedMatchers, T>;
|
} & BaseMatchers<R, T> & ToUserMatcherObject<ExtendedMatchers, R, T>;
|
||||||
|
|
||||||
export type Expect<ExtendedMatchers = {}> = {
|
export type Expect<ExtendedMatchers = {}> = {
|
||||||
<T = unknown>(actual: T, messageOrOptions?: string | { message?: string }): MakeMatchers<void, T, ExtendedMatchers>;
|
<T = unknown>(actual: T, messageOrOptions?: string | { message?: string }): MakeMatchers<void, T, ExtendedMatchers>;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user