Skip to content

Commit f92c27e

Browse files
committed
More more good typing jasmine test
1 parent 6397599 commit f92c27e

5 files changed

Lines changed: 532 additions & 707 deletions

File tree

jasmine-wdio-expect-async.d.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ declare namespace jasmine {
2020
*/
2121

2222
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- U is required to properly override Jasmine's AsyncMatchers
23-
interface AsyncMatchers<T, U> extends ExpectWebdriverIO.CustomMatchers<Promise<void>, T> {}
23+
interface AsyncMatchers<T, U> extends ExpectWebdriverIO.Matchers<Promise<void>, T> {}
2424

2525
// Needed to reference it below for the withContext method
2626
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -32,6 +32,15 @@ declare namespace ExpectWebdriverIO {
3232
// Should be the same as https://github.com/webdriverio/webdriverio/blob/ea0e3e00288abced4c739ff9e46c46977b7cdbd2/packages/wdio-jasmine-framework/src/index.ts#L21-L29
3333
interface JasmineAsymmetricMatchers extends Pick<ExpectWebdriverIO.AsymmetricMatchers, 'any' | 'anything' | 'arrayContaining' | 'objectContaining' | 'stringContaining' | 'stringMatching'> {}
3434

35+
// TODO dprevost review this!!!
36+
type JasmineSyncMatchers<T> = {
37+
[K in keyof jasmine.Matchers<T>]: K extends 'not'
38+
? JasmineSyncMatchers<T>
39+
: jasmine.Matchers<T>[K] extends (...args: any) => any
40+
? (...args: any[]) => Promise<void>
41+
: jasmine.Matchers<T>[K]
42+
}
43+
3544
/**
3645
* Overrides the default WDIO expect specifically for Jasmine, since `expectAsync` is forced into `expect`, making all matchers fully asynchronous. This is not the case under Jest or Mocha.
3746
* Using `jasmine.AsyncMatchers` includes the WdioMatchers from above, but also allows using Jasmine's built-in matchers and the `withContext` matcher.
@@ -48,8 +57,8 @@ declare namespace ExpectWebdriverIO {
4857
* @param actual The value to apply matchers against.
4958
*/
5059
<T = unknown>(actual: T): {
51-
withContext(message: string): jasmine.AsyncMatchers<T, Promise<void>> & jasmine.Matchers<T>;
52-
} & jasmine.AsyncMatchers<T, Promise<void>> & jasmine.Matchers<T>
60+
withContext(message: string): jasmine.AsyncMatchers<T, Promise<void>> & JasmineSyncMatchers<T>;
61+
} & jasmine.AsyncMatchers<T, Promise<void>> & JasmineSyncMatchers<T>
5362
}
5463
}
5564

0 commit comments

Comments
 (0)