chore: hide unsupported expect methods (#12403)

This commit is contained in:
Max Schmitt 2022-03-01 20:04:34 +01:00 committed by GitHub
parent 96945ab0a2
commit 5b7db90cb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,19 +31,21 @@ export declare type Expect = {
<T = unknown>(actual: T, message?: string): MakeMatchers<T>;
soft: <T = unknown>(actual: T, message?: string) => MakeMatchers<T>;
// Sourced from node_modules/expect/build/types.d.ts
assertions(arg0: number): void;
extend(arg0: any): void;
extractExpectedAssertionsErrors: typeof expect['extractExpectedAssertionsErrors'];
getState(): expect.MatcherState;
hasAssertions(): void;
setState(state: Partial<expect.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()
* - any()
* - anything()
*/
};
type ImageComparatorOptions = {
@ -54,18 +56,59 @@ type ImageComparatorOptions = {
type Awaited<T> = T extends PromiseLike<infer U> ? U : T;
type OverriddenExpectProperties =
'not' |
'resolves' |
'rejects' |
'toMatchInlineSnapshot' |
'toThrowErrorMatchingInlineSnapshot' |
'toMatchSnapshot' |
'toThrowErrorMatchingSnapshot';
/**
* Removed methods require the jest.fn() integration from Jest to spy on function calls which we don't support:
* - lastCalledWith()
* - lastReturnedWith()
* - nthCalledWith()
* - nthReturnedWith()
* - toBeCalled()
* - toBeCalledTimes()
* - toBeCalledWith()
* - toHaveBeenCalled()
* - toHaveBeenCalledTimes()
* - toHaveBeenCalledWith()
* - toHaveBeenLastCalledWith()
* - toHaveBeenNthCalledWith()
* - toHaveLastReturnedWith()
* - toHaveNthReturnedWith()
* - toHaveReturned()
* - toHaveReturnedTimes()
* - toHaveReturnedWith()
* - toReturn()
* - toReturnTimes()
* - toReturnWith()
* - toThrowErrorMatchingSnapshot()
* - toThrowErrorMatchingInlineSnapshot()
*/
type SupportedExpectProperties =
'toBe' |
'toBeCloseTo' |
'toBeDefined' |
'toBeFalsy' |
'toBeGreaterThan' |
'toBeGreaterThanOrEqual' |
'toBeInstanceOf' |
'toBeLessThan' |
'toBeLessThanOrEqual' |
'toBeNaN' |
'toBeNull' |
'toBeTruthy' |
'toBeUndefined' |
'toContain' |
'toContainEqual' |
'toEqual' |
'toHaveLength' |
'toHaveProperty' |
'toMatch' |
'toMatchObject' |
'toStrictEqual' |
'toThrow' |
'toThrowError'
declare global {
export namespace PlaywrightTest {
export interface Matchers<R> extends Omit<expect.Matchers<R>, OverriddenExpectProperties> {
export interface Matchers<R> extends Pick<expect.Matchers<R>, SupportedExpectProperties> {
/**
* If you know how to test something, `.not` lets you test its opposite.
*/