-
-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathjasmine-wdio-expect-async.d.ts
More file actions
49 lines (46 loc) · 2.22 KB
/
jasmine-wdio-expect-async.d.ts
File metadata and controls
49 lines (46 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/// <reference types="./types/expect-webdriverio.d.ts"/>
declare namespace jasmine {
/**
* Async matchers for Jasmine to allow the typing of `expectAsync` with WebDriverIO matchers.
* T is the type of the actual value
* U is the type of the expected value
* Both T,U must stay named as they are to override the default `AsyncMatchers` type from Jasmine.
*
* We force Matchers to return a `Promise<void>` since Jasmine's `expectAsync` expects a promise in all cases (different from Jest)
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface AsyncMatchers<T, U> extends Omit<ExpectWebdriverIO.Matchers<Promise<void>, T>, 'toMatchSnapshot' | 'toMatchInlineSnapshot'> {
/**
* snapshot matcher
* @param label optional snapshot label
*/
toMatchSnapshot(label?: string): Promise<void>;
/**
* inline snapshot matcher
* @param snapshot snapshot string (autogenerated if not specified)
* @param label optional snapshot label
*/
toMatchInlineSnapshot(snapshot?: string, label?: string): Promise<void>;
}
}
/**
* 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.
* Using `jasmine.AsyncMatchers` pull on WdioMatchers above but also allow to using Jasmine's built-in matchers and also `withContext` matcher.
*/
declare namespace ExpectWebdriverIO {
interface Expect {
/**
* The `expect` function is used every time you want to test a value.
* You will rarely call `expect` by itself.
*
* expect function declaration contains two generics:
* - T: the type of the actual value, e.g. any type, not just WebdriverIO.Browser or WebdriverIO.Element
* - R: the type of the return value, e.g. Promise<void> or void
*
* Note: The function must stay here in the namespace to overwrite correctly the expect function from the expect library.
*
* @param actual The value to apply matchers against.
*/
<T = unknown>(actual: T): jasmine.AsyncMatchers<T, void>
}
}