Skip to content

Commit 870aecd

Browse files
committed
FI-1743 fix: all expect methods should return Promise<void>
1 parent 7849902 commit 870aecd

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

autotests/tests/internalTypeTests/expect.skip.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ void expect(htmlElementSelector.textContent, '').toMatchScreenshot('some id');
2828

2929
// @ts-expect-error: eql is acceptable only for non-selectors
3030
void expect(htmlElementSelector, '').eql(htmlElementSelector);
31+
32+
// ok
33+
void (expect('foo', 'foo is correct').toBe('foo') satisfies Promise<void>);
34+
35+
// ok
36+
void (expect('foo', 'foo is correct').toBeDefined() satisfies Promise<void>);

src/expect.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import type {IsEqual, Selector} from './types/internal';
55
type ExpectFunction = SelectorExpect & NotSelectorExpect;
66

77
type NotSelectorExpect = <Actual>(
8+
this: void,
89
actual: IsEqual<Actual, Selector> extends true
910
? 'You should call some property or method on the selector'
1011
: Actual | Promise<Actual>,
1112
description: string,
1213
) => NonSelectorMatchers<Actual>;
1314

14-
type SelectorExpect = (actual: Selector, description: string) => SelectorMatchers;
15+
type SelectorExpect = (this: void, actual: Selector, description: string) => SelectorMatchers;
1516

1617
/**
1718
* Wraps a value or promised value to assertion for further checks.

src/utils/expect/types.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type {Expect as PlaywrightExpect} from '@playwright/test';
22

3-
import type {ToMatchScreenshotOptions} from '../../types/internal';
3+
import type {Fn, ToMatchScreenshotOptions} from '../../types/internal';
44

55
import type {Expect} from './Expect';
66

@@ -10,6 +10,8 @@ type EnsureString<Type> = Type extends string ? string : never;
1010

1111
type Extend<Type, Extended> = Type extends Extended ? Extended : never;
1212

13+
type PlaywrightMatchers = ReturnType<PlaywrightExpect>;
14+
1315
/**
1416
* All assertion functions keys (names of assertion functions, like `eql`, `match`, etc).
1517
* @internal
@@ -60,8 +62,13 @@ export type NonSelectorAdditionalMatchers<Actual> = Readonly<{
6062
/**
6163
* All matchers.
6264
*/
63-
export type NonSelectorMatchers<Actual> = NonSelectorAdditionalMatchers<Actual> &
64-
ReturnType<PlaywrightExpect>;
65+
export type NonSelectorMatchers<Actual> = NonSelectorAdditionalMatchers<Actual> & {
66+
readonly [Key in keyof PlaywrightMatchers]: Fn<
67+
PlaywrightMatchers[Key] extends (...args: infer Args) => unknown ? Args : never,
68+
Promise<void>,
69+
void
70+
>;
71+
};
6572

6673
/**
6774
* Matchers for selector.

0 commit comments

Comments
 (0)