fix(expect): expect.not types (#15487)
This commit is contained in:
parent
67a2f948fd
commit
98ea418124
|
|
@ -327,7 +327,7 @@ Playwright Trace Viewer is now **available online** at https://trace.playwright.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Ubuntu ARM64 support + more
|
### Ubuntu ARM64 support + more
|
||||||
|
|
||||||
- Playwright now supports **Ubuntu 20.04 ARM64**. You can now run Playwright tests inside Docker on Apple M1 and on Raspberry Pi.
|
- Playwright now supports **Ubuntu 20.04 ARM64**. You can now run Playwright tests inside Docker on Apple M1 and on Raspberry Pi.
|
||||||
- You can now use Playwright to install stable version of Edge on Linux:
|
- You can now use Playwright to install stable version of Edge on Linux:
|
||||||
|
|
|
||||||
47
packages/playwright-test/types/test.d.ts
vendored
47
packages/playwright-test/types/test.d.ts
vendored
|
|
@ -3029,6 +3029,23 @@ import type { Suite } from '@playwright/test/types/testReporter';
|
||||||
|
|
||||||
type AsymmetricMatcher = Record<string, any>;
|
type AsymmetricMatcher = Record<string, any>;
|
||||||
|
|
||||||
|
type AsymmetricMatchers = {
|
||||||
|
any(sample: unknown): AsymmetricMatcher;
|
||||||
|
anything(): AsymmetricMatcher;
|
||||||
|
arrayContaining(sample: Array<unknown>): AsymmetricMatcher;
|
||||||
|
closeTo(sample: number, precision?: number): AsymmetricMatcher;
|
||||||
|
objectContaining(sample: Record<string, unknown>): AsymmetricMatcher;
|
||||||
|
stringContaining(sample: string): AsymmetricMatcher;
|
||||||
|
stringMatching(sample: string | RegExp): AsymmetricMatcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
type Inverse<Matchers> = {
|
||||||
|
/**
|
||||||
|
* Inverse next matcher. If you know how to test something, `.not` lets you test its opposite.
|
||||||
|
*/
|
||||||
|
not: Matchers;
|
||||||
|
};
|
||||||
|
|
||||||
type IfAny<T, Y, N> = 0 extends (1 & T) ? Y : N;
|
type IfAny<T, Y, N> = 0 extends (1 & T) ? Y : N;
|
||||||
type ExtraMatchers<T, Type, Matchers> = T extends Type ? Matchers : IfAny<T, Matchers, {}>;
|
type ExtraMatchers<T, Type, Matchers> = T extends Type ? Matchers : IfAny<T, Matchers, {}>;
|
||||||
|
|
||||||
|
|
@ -3054,6 +3071,16 @@ type MakeMatchers<R, T> = BaseMatchers<R, T> & {
|
||||||
ExtraMatchers<T, Locator, LocatorAssertions> &
|
ExtraMatchers<T, Locator, LocatorAssertions> &
|
||||||
ExtraMatchers<T, APIResponse, APIResponseAssertions>;
|
ExtraMatchers<T, APIResponse, APIResponseAssertions>;
|
||||||
|
|
||||||
|
type BaseExpect = {
|
||||||
|
// Removed following methods because they rely on a test-runner integration from Jest which we don't support:
|
||||||
|
// assertions(numberOfAssertions: number): void;
|
||||||
|
// extractExpectedAssertionsErrors(): ExpectedAssertionsErrors;
|
||||||
|
// hasAssertions(): void;
|
||||||
|
extend(matchers: any): void;
|
||||||
|
getState(): expectType.MatcherState;
|
||||||
|
setState(state: Partial<expectType.MatcherState>): void;
|
||||||
|
}
|
||||||
|
|
||||||
export type Expect = {
|
export type Expect = {
|
||||||
<T = unknown>(actual: T, messageOrOptions?: string | { message?: string }): MakeMatchers<void, T>;
|
<T = unknown>(actual: T, messageOrOptions?: string | { message?: string }): MakeMatchers<void, T>;
|
||||||
soft: <T = unknown>(actual: T, messageOrOptions?: string | { message?: string }) => MakeMatchers<void, T>;
|
soft: <T = unknown>(actual: T, messageOrOptions?: string | { message?: string }) => MakeMatchers<void, T>;
|
||||||
|
|
@ -3063,23 +3090,9 @@ export type Expect = {
|
||||||
*/
|
*/
|
||||||
not: BaseMatchers<Promise<void>, T>;
|
not: BaseMatchers<Promise<void>, T>;
|
||||||
};
|
};
|
||||||
|
} & BaseExpect &
|
||||||
extend(arg0: any): void;
|
AsymmetricMatchers &
|
||||||
getState(): expectType.MatcherState;
|
Inverse<Omit<AsymmetricMatchers, 'any' | 'anything'>>;
|
||||||
setState(state: Partial<expectType.MatcherState>): void;
|
|
||||||
any(expectedObject: any): AsymmetricMatcher;
|
|
||||||
anything(): AsymmetricMatcher;
|
|
||||||
arrayContaining(sample: Array<unknown>): AsymmetricMatcher;
|
|
||||||
objectContaining(sample: Record<string, unknown>): AsymmetricMatcher;
|
|
||||||
stringContaining(expected: string): AsymmetricMatcher;
|
|
||||||
stringMatching(expected: string | RegExp): AsymmetricMatcher;
|
|
||||||
/**
|
|
||||||
* Removed following methods because they rely on a test-runner integration from Jest which we don't support:
|
|
||||||
* - assertions()
|
|
||||||
* - extractExpectedAssertionsErrors()
|
|
||||||
* – hasAssertions()
|
|
||||||
*/
|
|
||||||
};
|
|
||||||
|
|
||||||
type Awaited<T> = T extends PromiseLike<infer U> ? U : T;
|
type Awaited<T> = T extends PromiseLike<infer U> ? U : T;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,7 @@ test('should work with default expect prototype functions', async ({ runTSC, run
|
||||||
);
|
);
|
||||||
expect('foo').toEqual(expect.any(String));
|
expect('foo').toEqual(expect.any(String));
|
||||||
expect('foo').toEqual(expect.anything());
|
expect('foo').toEqual(expect.anything());
|
||||||
|
expect('hello world').toEqual(expect.not.stringContaining('text'));
|
||||||
});
|
});
|
||||||
`;
|
`;
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,6 @@ class TypesGenerator {
|
||||||
return this.writeComment(docClass.comment) + '\n';
|
return this.writeComment(docClass.comment) + '\n';
|
||||||
}, (className, methodName, overloadIndex) => {
|
}, (className, methodName, overloadIndex) => {
|
||||||
if (className === 'SuiteFunction' && methodName === '__call') {
|
if (className === 'SuiteFunction' && methodName === '__call') {
|
||||||
console.log(className, methodName, overloadIndex);
|
|
||||||
const cls = this.documentation.classes.get('Test');
|
const cls = this.documentation.classes.get('Test');
|
||||||
const method = cls.membersArray.find(m => m.alias === 'describe' && m.overloadIndex === overloadIndex);
|
const method = cls.membersArray.find(m => m.alias === 'describe' && m.overloadIndex === overloadIndex);
|
||||||
return this.memberJSDOC(method, ' ').trimLeft();
|
return this.memberJSDOC(method, ' ').trimLeft();
|
||||||
|
|
|
||||||
47
utils/generate_types/overrides-test.d.ts
vendored
47
utils/generate_types/overrides-test.d.ts
vendored
|
|
@ -256,6 +256,23 @@ import type { Suite } from '@playwright/test/types/testReporter';
|
||||||
|
|
||||||
type AsymmetricMatcher = Record<string, any>;
|
type AsymmetricMatcher = Record<string, any>;
|
||||||
|
|
||||||
|
type AsymmetricMatchers = {
|
||||||
|
any(sample: unknown): AsymmetricMatcher;
|
||||||
|
anything(): AsymmetricMatcher;
|
||||||
|
arrayContaining(sample: Array<unknown>): AsymmetricMatcher;
|
||||||
|
closeTo(sample: number, precision?: number): AsymmetricMatcher;
|
||||||
|
objectContaining(sample: Record<string, unknown>): AsymmetricMatcher;
|
||||||
|
stringContaining(sample: string): AsymmetricMatcher;
|
||||||
|
stringMatching(sample: string | RegExp): AsymmetricMatcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
type Inverse<Matchers> = {
|
||||||
|
/**
|
||||||
|
* Inverse next matcher. If you know how to test something, `.not` lets you test its opposite.
|
||||||
|
*/
|
||||||
|
not: Matchers;
|
||||||
|
};
|
||||||
|
|
||||||
type IfAny<T, Y, N> = 0 extends (1 & T) ? Y : N;
|
type IfAny<T, Y, N> = 0 extends (1 & T) ? Y : N;
|
||||||
type ExtraMatchers<T, Type, Matchers> = T extends Type ? Matchers : IfAny<T, Matchers, {}>;
|
type ExtraMatchers<T, Type, Matchers> = T extends Type ? Matchers : IfAny<T, Matchers, {}>;
|
||||||
|
|
||||||
|
|
@ -281,6 +298,16 @@ type MakeMatchers<R, T> = BaseMatchers<R, T> & {
|
||||||
ExtraMatchers<T, Locator, LocatorAssertions> &
|
ExtraMatchers<T, Locator, LocatorAssertions> &
|
||||||
ExtraMatchers<T, APIResponse, APIResponseAssertions>;
|
ExtraMatchers<T, APIResponse, APIResponseAssertions>;
|
||||||
|
|
||||||
|
type BaseExpect = {
|
||||||
|
// Removed following methods because they rely on a test-runner integration from Jest which we don't support:
|
||||||
|
// assertions(numberOfAssertions: number): void;
|
||||||
|
// extractExpectedAssertionsErrors(): ExpectedAssertionsErrors;
|
||||||
|
// hasAssertions(): void;
|
||||||
|
extend(matchers: any): void;
|
||||||
|
getState(): expectType.MatcherState;
|
||||||
|
setState(state: Partial<expectType.MatcherState>): void;
|
||||||
|
}
|
||||||
|
|
||||||
export type Expect = {
|
export type Expect = {
|
||||||
<T = unknown>(actual: T, messageOrOptions?: string | { message?: string }): MakeMatchers<void, T>;
|
<T = unknown>(actual: T, messageOrOptions?: string | { message?: string }): MakeMatchers<void, T>;
|
||||||
soft: <T = unknown>(actual: T, messageOrOptions?: string | { message?: string }) => MakeMatchers<void, T>;
|
soft: <T = unknown>(actual: T, messageOrOptions?: string | { message?: string }) => MakeMatchers<void, T>;
|
||||||
|
|
@ -290,23 +317,9 @@ export type Expect = {
|
||||||
*/
|
*/
|
||||||
not: BaseMatchers<Promise<void>, T>;
|
not: BaseMatchers<Promise<void>, T>;
|
||||||
};
|
};
|
||||||
|
} & BaseExpect &
|
||||||
extend(arg0: any): void;
|
AsymmetricMatchers &
|
||||||
getState(): expectType.MatcherState;
|
Inverse<Omit<AsymmetricMatchers, 'any' | 'anything'>>;
|
||||||
setState(state: Partial<expectType.MatcherState>): void;
|
|
||||||
any(expectedObject: any): AsymmetricMatcher;
|
|
||||||
anything(): AsymmetricMatcher;
|
|
||||||
arrayContaining(sample: Array<unknown>): AsymmetricMatcher;
|
|
||||||
objectContaining(sample: Record<string, unknown>): AsymmetricMatcher;
|
|
||||||
stringContaining(expected: string): AsymmetricMatcher;
|
|
||||||
stringMatching(expected: string | RegExp): AsymmetricMatcher;
|
|
||||||
/**
|
|
||||||
* Removed following methods because they rely on a test-runner integration from Jest which we don't support:
|
|
||||||
* - assertions()
|
|
||||||
* - extractExpectedAssertionsErrors()
|
|
||||||
* – hasAssertions()
|
|
||||||
*/
|
|
||||||
};
|
|
||||||
|
|
||||||
type Awaited<T> = T extends PromiseLike<infer U> ? U : T;
|
type Awaited<T> = T extends PromiseLike<infer U> ? U : T;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue