expect-webdriverio 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +65 -0
  3. package/jasmine.d.ts +6 -0
  4. package/jest.d.ts +5 -0
  5. package/lib/addMatchers.js +48 -0
  6. package/lib/index.js +6 -0
  7. package/lib/jasmineUtils.js +205 -0
  8. package/lib/matchers/browser/toHaveTitle.js +26 -0
  9. package/lib/matchers/browser/toHaveTitleContaining.js +15 -0
  10. package/lib/matchers/browser/toHaveUrl.js +26 -0
  11. package/lib/matchers/browser/toHaveUrlContaining.js +15 -0
  12. package/lib/matchers/element/toBeClickable.js +23 -0
  13. package/lib/matchers/element/toBeDisabled.js +16 -0
  14. package/lib/matchers/element/toBeDisplayed.js +23 -0
  15. package/lib/matchers/element/toBeDisplayedInViewport.js +23 -0
  16. package/lib/matchers/element/toBeEnabled.js +16 -0
  17. package/lib/matchers/element/toBeExisting.js +32 -0
  18. package/lib/matchers/element/toBeFocused.js +16 -0
  19. package/lib/matchers/element/toBeSelected.js +22 -0
  20. package/lib/matchers/element/toHaveAttribute.js +72 -0
  21. package/lib/matchers/element/toHaveAttributeContaining.js +16 -0
  22. package/lib/matchers/element/toHaveChildren.js +51 -0
  23. package/lib/matchers/element/toHaveElementClass.js +60 -0
  24. package/lib/matchers/element/toHaveElementClassContaining.js +20 -0
  25. package/lib/matchers/element/toHaveElementProperty.js +52 -0
  26. package/lib/matchers/element/toHaveHref.js +14 -0
  27. package/lib/matchers/element/toHaveHrefContaining.js +16 -0
  28. package/lib/matchers/element/toHaveId.js +13 -0
  29. package/lib/matchers/element/toHaveStyle.js +33 -0
  30. package/lib/matchers/element/toHaveText.js +37 -0
  31. package/lib/matchers/element/toHaveTextContaining.js +15 -0
  32. package/lib/matchers/element/toHaveValue.js +13 -0
  33. package/lib/matchers/element/toHaveValueContaining.js +15 -0
  34. package/lib/matchers/elements/toBeElementsArrayOfSize.js +39 -0
  35. package/lib/matchers/mock/toBeRequested.js +12 -0
  36. package/lib/matchers/mock/toBeRequestedTimes.js +35 -0
  37. package/lib/matchers/mock/toBeRequestedWith.js +218 -0
  38. package/lib/matchers/mock/toBeRequestedWithResponse.js +13 -0
  39. package/lib/matchers.js +41 -0
  40. package/lib/options.js +33 -0
  41. package/lib/util/elementsUtil.js +28 -0
  42. package/lib/util/executeCommand.js +31 -0
  43. package/lib/util/expectAdapter.js +41 -0
  44. package/lib/util/formatMessage.js +93 -0
  45. package/lib/util/refetchElements.js +15 -0
  46. package/lib/utils.js +161 -0
  47. package/package.json +68 -0
  48. package/types/expect-webdriverio.d.ts +327 -0
  49. package/types/jest-global.d.ts +9 -0
  50. package/types/standalone-global.d.ts +9 -0
  51. package/types/standalone.d.ts +24 -0
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "expect-webdriverio",
3
+ "version": "4.0.0",
4
+ "description": "",
5
+ "main": "lib/index.js",
6
+ "scripts": {
7
+ "build": "run-s clean compile",
8
+ "clean": "run-p clean:*",
9
+ "clean:build": "rimraf ./lib",
10
+ "clean:tests": "rimraf test-types/**/node_modules && rimraf test-types/**/dist",
11
+ "compile": "tsc --build tsconfig.build.json",
12
+ "release": "release-it --github.release",
13
+ "release:ci": "npm run release -- --ci --npm.skipChecks --no-git.requireCleanWorkingDir",
14
+ "release:patch": "npm run release -- patch",
15
+ "release:minor": "npm run release -- minor",
16
+ "release:major": "npm run release -- major",
17
+ "test": "run-s test:*",
18
+ "test:lint": "eslint . --ext .js,.jsx,.ts,.tsx",
19
+ "test:unit": "jest",
20
+ "watch": "npm run compile -- --watch",
21
+ "test:types": "node test-types/copy && npm run ts && npm run clean:tests",
22
+ "ts": "run-p ts:*",
23
+ "ts:default": "cd test-types/default && tsc --incremental",
24
+ "ts:jest": "cd test-types/jest && tsc --incremental",
25
+ "ts:jasmine": "cd test-types/jasmine && tsc --incremental",
26
+ "prepare": "husky install"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/webdriverio/expect-webdriverio.git"
31
+ },
32
+ "keywords": [
33
+ "expect-webdriverio",
34
+ "expect",
35
+ "webdriverio",
36
+ "wdio"
37
+ ],
38
+ "author": "Mykola Grybyk <mykola.grybyk@gmail.com>",
39
+ "license": "MIT",
40
+ "bugs": {
41
+ "url": "https://github.com/webdriverio/expect-webdriverio/issues"
42
+ },
43
+ "homepage": "https://github.com/webdriverio/expect-webdriverio#readme",
44
+ "devDependencies": {
45
+ "@types/jasmine": "^3.6.6",
46
+ "@types/jest": "^27.0.1",
47
+ "@types/node": "^15.0.1",
48
+ "@typescript-eslint/eslint-plugin": "^4.17.0",
49
+ "@typescript-eslint/parser": "^4.17.0",
50
+ "eslint": "^7.21.0",
51
+ "husky": "^7.0.0",
52
+ "jest": "^26.6.3",
53
+ "npm-run-all": "^4.1.5",
54
+ "release-it": "^14.4.1",
55
+ "rimraf": "^3.0.2",
56
+ "shelljs": "^0.8.4",
57
+ "ts-jest": "^26.5.3",
58
+ "ts-node": "^10.0.0",
59
+ "typescript": "^4.2.3",
60
+ "webdriverio": "^7.1.1"
61
+ },
62
+ "types": "types/jest-global.d.ts",
63
+ "typeScriptVersion": "3.8.3",
64
+ "dependencies": {
65
+ "expect": "^27.0.2",
66
+ "jest-matcher-utils": "^27.0.2"
67
+ }
68
+ }
@@ -0,0 +1,327 @@
1
+ declare namespace ExpectWebdriverIO {
2
+ function setOptions(options: DefaultOptions): void
3
+
4
+ interface DefaultOptions {
5
+ /**
6
+ * time in ms to wait for expectation to succeed. Default: 3000
7
+ */
8
+ wait?: number
9
+
10
+ /**
11
+ * interval between attempts. Default: 100
12
+ */
13
+ interval?: number
14
+ }
15
+
16
+ interface CommandOptions extends DefaultOptions {
17
+ /**
18
+ * user message to prepend before assertion error
19
+ */
20
+ message?: string
21
+ }
22
+
23
+ interface StringOptions extends CommandOptions {
24
+ /**
25
+ * apply `toLowerCase` to both actual and expected values
26
+ */
27
+ ignoreCase?: boolean
28
+
29
+ /**
30
+ * apply `trim` to actual value
31
+ */
32
+ trim?: boolean
33
+
34
+ /**
35
+ * expect actual value to contain expected value.
36
+ * Otherwise strict equal
37
+ */
38
+ containing?: boolean
39
+
40
+ /**
41
+ * might be helpful to force converting property value to string
42
+ */
43
+ asString?: boolean
44
+ }
45
+
46
+ interface NumberOptions extends CommandOptions {
47
+ /**
48
+ * equals
49
+ */
50
+ eq?: number
51
+ /**
52
+ * less than or equals
53
+ */
54
+ lte?: number
55
+
56
+ /**
57
+ * greater than or equals
58
+ */
59
+ gte?: number
60
+ }
61
+
62
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
63
+ interface Matchers<R, T> {
64
+ // ===== $ or $$ =====
65
+ /**
66
+ * `WebdriverIO.Element` -> `isDisplayed`
67
+ */
68
+ toBeDisplayed(options?: ExpectWebdriverIO.CommandOptions): R
69
+
70
+ /**
71
+ * `WebdriverIO.Element` -> `isExisting`
72
+ */
73
+ toExist(options?: ExpectWebdriverIO.CommandOptions): R
74
+ /**
75
+ * `WebdriverIO.Element` -> `isExisting`
76
+ */
77
+ toBePresent(options?: ExpectWebdriverIO.CommandOptions): R
78
+ /**
79
+ * `WebdriverIO.Element` -> `isExisting`
80
+ */
81
+ toBeExisting(options?: ExpectWebdriverIO.CommandOptions): R
82
+
83
+ /**
84
+ * `WebdriverIO.Element` -> `getAttribute`
85
+ */
86
+ toHaveAttribute(attribute: string, value?: string, options?: ExpectWebdriverIO.StringOptions): R
87
+ /**
88
+ * `WebdriverIO.Element` -> `getAttribute`
89
+ */
90
+ toHaveAttr(attribute: string, value?: string, options?: ExpectWebdriverIO.StringOptions): R
91
+
92
+ /**
93
+ * `WebdriverIO.Element` -> `getAttribute`
94
+ * Element's attribute includes the value.
95
+ */
96
+ toHaveAttributeContaining(
97
+ attribute: string,
98
+ contains: string,
99
+ options?: ExpectWebdriverIO.StringOptions
100
+ ): R
101
+ /**
102
+ * `WebdriverIO.Element` -> `getAttribute`
103
+ * Element's attribute includes the value.
104
+ */
105
+ toHaveAttrContaining(
106
+ attribute: string,
107
+ contains: string,
108
+ options?: ExpectWebdriverIO.StringOptions
109
+ ): R
110
+
111
+ /**
112
+ * `WebdriverIO.Element` -> `getAttribute` class
113
+ * @deprecated since v1.3.1 - use `toHaveElementClass` instead.
114
+ */
115
+ toHaveClass(className: string, options?: ExpectWebdriverIO.StringOptions): R
116
+
117
+ /**
118
+ * `WebdriverIO.Element` -> `getAttribute` class
119
+ */
120
+ toHaveElementClass(className: string, options?: ExpectWebdriverIO.StringOptions): R
121
+
122
+ /**
123
+ * `WebdriverIO.Element` -> `getAttribute` class
124
+ * @deprecated since v1.3.1 - use `toHaveElementClassContaining` instead.
125
+ * Element's class includes the className.
126
+ */
127
+ toHaveClassContaining(className: string, options?: ExpectWebdriverIO.StringOptions): R
128
+
129
+ /**
130
+ * `WebdriverIO.Element` -> `getAttribute` class
131
+ * Element's class includes the className.
132
+ */
133
+ toHaveElementClassContaining(className: string, options?: ExpectWebdriverIO.StringOptions): R
134
+
135
+ /**
136
+ * `WebdriverIO.Element` -> `getProperty`
137
+ */
138
+ toHaveElementProperty(property: string, value?: any, options?: ExpectWebdriverIO.StringOptions): R
139
+
140
+ /**
141
+ * `WebdriverIO.Element` -> `getProperty` value
142
+ */
143
+ toHaveValue(value: string, options?: ExpectWebdriverIO.StringOptions): R
144
+ /**
145
+ * `WebdriverIO.Element` -> `getProperty` value
146
+ * Element's value includes the value.
147
+ */
148
+ toHaveValueContaining(value: string, options?: ExpectWebdriverIO.StringOptions): R
149
+
150
+ /**
151
+ * `WebdriverIO.Element` -> `isClickable`
152
+ */
153
+ toBeClickable(options?: ExpectWebdriverIO.StringOptions): R
154
+
155
+ /**
156
+ * `WebdriverIO.Element` -> `!isEnabled`
157
+ */
158
+ toBeDisabled(options?: ExpectWebdriverIO.StringOptions): R
159
+
160
+ /**
161
+ * `WebdriverIO.Element` -> `isDisplayedInViewport`
162
+ */
163
+ toBeDisplayedInViewport(options?: ExpectWebdriverIO.StringOptions): R
164
+
165
+ /**
166
+ * `WebdriverIO.Element` -> `isEnabled`
167
+ */
168
+ toBeEnabled(options?: ExpectWebdriverIO.StringOptions): R
169
+
170
+ /**
171
+ * `WebdriverIO.Element` -> `isFocused`
172
+ */
173
+ toBeFocused(options?: ExpectWebdriverIO.StringOptions): R
174
+
175
+ /**
176
+ * `WebdriverIO.Element` -> `isSelected`
177
+ */
178
+ toBeSelected(options?: ExpectWebdriverIO.StringOptions): R
179
+
180
+ /**
181
+ * `WebdriverIO.Element` -> `isSelected`
182
+ */
183
+ toBeChecked(options?: ExpectWebdriverIO.StringOptions): R
184
+
185
+ /**
186
+ * `WebdriverIO.Element` -> `$$('./*').length`
187
+ * supports less / greater then or equals to be passed in options
188
+ */
189
+ toHaveChildren(
190
+ size?: number | ExpectWebdriverIO.NumberOptions,
191
+ options?: ExpectWebdriverIO.NumberOptions
192
+ ): R
193
+
194
+ /**
195
+ * `WebdriverIO.Element` -> `getAttribute` href
196
+ */
197
+ toHaveHref(href: string, options?: ExpectWebdriverIO.StringOptions): R
198
+ /**
199
+ * `WebdriverIO.Element` -> `getAttribute` href
200
+ */
201
+ toHaveLink(href: string, options?: ExpectWebdriverIO.StringOptions): R
202
+
203
+ /**
204
+ * `WebdriverIO.Element` -> `getAttribute` href
205
+ * Element's href includes the value provided
206
+ */
207
+ toHaveHrefContaining(href: string, options?: ExpectWebdriverIO.StringOptions): R
208
+ /**
209
+ * `WebdriverIO.Element` -> `getAttribute` href
210
+ * Element's href includes the value provided
211
+ */
212
+ toHaveLinkContaining(href: string, options?: ExpectWebdriverIO.StringOptions): R
213
+
214
+ /**
215
+ * `WebdriverIO.Element` -> `getProperty` value
216
+ */
217
+ toHaveId(id: string, options?: ExpectWebdriverIO.StringOptions): R
218
+
219
+ /**
220
+ * `WebdriverIO.Element` -> `getText`
221
+ */
222
+ toHaveText(text: string | string[], options?: ExpectWebdriverIO.StringOptions): R
223
+ /**
224
+ * `WebdriverIO.Element` -> `getText`
225
+ * Element's text includes the text provided
226
+ */
227
+ toHaveTextContaining(text: string | string[], options?: ExpectWebdriverIO.StringOptions): R
228
+
229
+ /**
230
+ * `WebdriverIO.Element` -> `getAttribute("style")`
231
+ */
232
+ toHaveStyle(style: { [key: string]: string; }, options?: ExpectWebdriverIO.StringOptions): R
233
+
234
+ // ===== browser only =====
235
+ /**
236
+ * `WebdriverIO.Browser` -> `getUrl`
237
+ */
238
+ toHaveUrl(url: string, options?: ExpectWebdriverIO.StringOptions): R
239
+
240
+ // ===== browser only =====
241
+ /**
242
+ * `WebdriverIO.Browser` -> `getUrl`
243
+ * Browser's url includes the provided text
244
+ */
245
+ toHaveUrlContaining(url: string, options?: ExpectWebdriverIO.StringOptions): R
246
+
247
+ /**
248
+ * `WebdriverIO.Browser` -> `getTitle`
249
+ */
250
+ toHaveTitle(title: string, options?: ExpectWebdriverIO.StringOptions): R
251
+
252
+ // ===== browser only =====
253
+ /**
254
+ * `WebdriverIO.Browser` -> `getTitle`
255
+ * Browser's title includes the provided text
256
+ */
257
+ toHaveTitleContaining(title: string, options?: ExpectWebdriverIO.StringOptions): R
258
+
259
+ // ===== $$ only =====
260
+ /**
261
+ * `WebdriverIO.ElementArray` -> `$$('...').length`
262
+ * supports less / greater then or equals to be passed in options
263
+ */
264
+ toBeElementsArrayOfSize(
265
+ size: number | ExpectWebdriverIO.NumberOptions,
266
+ options?: ExpectWebdriverIO.NumberOptions
267
+ ): R
268
+
269
+ // ==== network mock ====
270
+
271
+ /**
272
+ * Check that `WebdriverIO.Mock` was called
273
+ */
274
+ toBeRequested(options?: ExpectWebdriverIO.CommandOptions): R
275
+
276
+ /**
277
+ * Check that `WebdriverIO.Mock` was called N times
278
+ */
279
+ toBeRequestedTimes(
280
+ times: number | ExpectWebdriverIO.NumberOptions,
281
+ options?: ExpectWebdriverIO.NumberOptions
282
+ ): R
283
+
284
+ /**
285
+ * Check that `WebdriverIO.Mock` was called with the specific parameters
286
+ */
287
+ toBeRequestedWith(requestedWith: RequestedWith, options?: ExpectWebdriverIO.CommandOptions): R
288
+ }
289
+
290
+ type RequestedWith = {
291
+ url?: string | ExpectWebdriverIO.PartialMatcher | ((url: string) => boolean)
292
+ method?: string | Array<string>
293
+ statusCode?: number | Array<number>
294
+ requestHeaders?:
295
+ | Record<string, string>
296
+ | ExpectWebdriverIO.PartialMatcher
297
+ | ((headers: Record<string, string>) => boolean)
298
+ responseHeaders?:
299
+ | Record<string, string>
300
+ | ExpectWebdriverIO.PartialMatcher
301
+ | ((headers: Record<string, string>) => boolean)
302
+ postData?:
303
+ | string
304
+ | ExpectWebdriverIO.JsonCompatible
305
+ | ExpectWebdriverIO.PartialMatcher
306
+ | ((r: string | undefined) => boolean)
307
+ response?:
308
+ | string
309
+ | ExpectWebdriverIO.JsonCompatible
310
+ | ExpectWebdriverIO.PartialMatcher
311
+ | ((r: string) => boolean)
312
+ }
313
+
314
+ type jsonPrimitive = string | number | boolean | null
315
+ type jsonObject = { [x: string]: jsonPrimitive | jsonObject | jsonArray }
316
+ type jsonArray = Array<jsonPrimitive | jsonObject | jsonArray>
317
+ type JsonCompatible = jsonObject | jsonArray
318
+
319
+ interface PartialMatcher {
320
+ sample?: any
321
+ asymmetricMatch?(...args: any[]): boolean
322
+ }
323
+ }
324
+
325
+ declare module 'expect-webdriverio' {
326
+ export = ExpectWebdriverIO
327
+ }
@@ -0,0 +1,9 @@
1
+ /// <reference types="expect-webdriverio/types/standalone"/>
2
+
3
+ declare const expect: ExpectWebdriverIO.Expect
4
+
5
+ declare namespace NodeJS {
6
+ interface Global {
7
+ expect: ExpectWebdriverIO.Expect;
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ /// <reference types="expect-webdriverio/types/standalone"/>
2
+
3
+ declare const expectWdio: ExpectWebdriverIO.Expect
4
+
5
+ declare namespace NodeJS {
6
+ interface Global {
7
+ expectWdio: ExpectWebdriverIO.Expect;
8
+ }
9
+ }
@@ -0,0 +1,24 @@
1
+ /// <reference types="expect-webdriverio/types/expect-webdriverio"/>
2
+
3
+ declare namespace ExpectWebdriverIO {
4
+ interface Matchers<R, T> extends Readonly<import('expect/build/types').Matchers<R>> {
5
+ not: Matchers<R, T>
6
+ resolves: Matchers<Promise<R>, T>
7
+ rejects: Matchers<Promise<R>, T>
8
+ }
9
+
10
+ type Expect = {
11
+ <T = unknown>(actual: T): Matchers<T, T>
12
+ extend(map: Record<string, Function>): void
13
+ } & AsymmetricMatchers
14
+
15
+ type AsymmetricMatchers = {
16
+ any(expectedObject: any): PartialMatcher
17
+ anything(): PartialMatcher
18
+ arrayContaining(sample: Array<unknown>): PartialMatcher
19
+ objectContaining(sample: Record<string, unknown>): PartialMatcher
20
+ stringContaining(expected: string): PartialMatcher
21
+ stringMatching(expected: string | RegExp): PartialMatcher
22
+ not: AsymmetricMatchers
23
+ }
24
+ }