expect-webdriverio 2.0.0 → 2.0.1

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 (43) hide show
  1. package/README.md +1 -1
  2. package/lib/addMatchers.js +48 -0
  3. package/lib/index.js +6 -0
  4. package/lib/jasmineUtils.js +205 -0
  5. package/lib/matchers/browser/toHaveTitle.js +26 -0
  6. package/lib/matchers/browser/toHaveTitleContaining.js +15 -0
  7. package/lib/matchers/browser/toHaveUrl.js +26 -0
  8. package/lib/matchers/browser/toHaveUrlContaining.js +15 -0
  9. package/lib/matchers/element/toBeClickable.js +23 -0
  10. package/lib/matchers/element/toBeDisabled.js +16 -0
  11. package/lib/matchers/element/toBeDisplayed.js +27 -0
  12. package/lib/matchers/element/toBeDisplayedInViewport.js +27 -0
  13. package/lib/matchers/element/toBeEnabled.js +16 -0
  14. package/lib/matchers/element/toBeExisting.js +32 -0
  15. package/lib/matchers/element/toBeFocused.js +16 -0
  16. package/lib/matchers/element/toBeSelected.js +22 -0
  17. package/lib/matchers/element/toHaveAttribute.js +48 -0
  18. package/lib/matchers/element/toHaveAttributeContaining.js +16 -0
  19. package/lib/matchers/element/toHaveChildren.js +47 -0
  20. package/lib/matchers/element/toHaveElementClass.js +60 -0
  21. package/lib/matchers/element/toHaveElementClassContaining.js +20 -0
  22. package/lib/matchers/element/toHaveElementProperty.js +52 -0
  23. package/lib/matchers/element/toHaveHref.js +14 -0
  24. package/lib/matchers/element/toHaveHrefContaining.js +16 -0
  25. package/lib/matchers/element/toHaveId.js +13 -0
  26. package/lib/matchers/element/toHaveText.js +37 -0
  27. package/lib/matchers/element/toHaveTextContaining.js +15 -0
  28. package/lib/matchers/element/toHaveValue.js +13 -0
  29. package/lib/matchers/element/toHaveValueContaining.js +15 -0
  30. package/lib/matchers/elements/toBeElementsArrayOfSize.js +41 -0
  31. package/lib/matchers/mock/toBeRequested.js +12 -0
  32. package/lib/matchers/mock/toBeRequestedTimes.js +37 -0
  33. package/lib/matchers/mock/toBeRequestedWith.js +218 -0
  34. package/lib/matchers/mock/toBeRequestedWithResponse.js +13 -0
  35. package/lib/matchers.js +40 -0
  36. package/lib/options.js +33 -0
  37. package/lib/util/elementsUtil.js +26 -0
  38. package/lib/util/executeCommand.js +31 -0
  39. package/lib/util/expectAdapter.js +39 -0
  40. package/lib/util/formatMessage.js +87 -0
  41. package/lib/util/refetchElements.js +15 -0
  42. package/lib/utils.js +131 -0
  43. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # expect-webdriverio
2
2
 
3
- [![Build Status](https://travis-ci.org/webdriverio/expect-webdriverio.svg?branch=main)](https://travis-ci.org/webdriverio/expect-webdriverio) [![codecov](https://codecov.io/gh/webdriverio/expect-webdriverio/branch/main/graph/badge.svg)](https://codecov.io/gh/webdriverio/expect-webdriverio)
3
+ [![Test](https://github.com/webdriverio/expect-webdriverio/actions/workflows/test.yml/badge.svg)](https://github.com/webdriverio/expect-webdriverio/actions/workflows/test.yml)
4
4
 
5
5
  ###### [API](docs/API.md) | [TypeScript / JS Autocomplete](/docs/Types.md) | [Examples](docs/Examples.md) | [Extending Matchers](/docs/Extend.md)
6
6
 
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addMatchers = exports.loadExpect = exports.isJasmine = void 0;
4
+ let expectLib;
5
+ const isJasmine = () => {
6
+ return Boolean(global.jasmine && global.expect && global.expectAsync && global.jasmine.getEnv && global.jasmine.addMatchers && global.jasmine.addAsyncMatchers);
7
+ };
8
+ exports.isJasmine = isJasmine;
9
+ const loadExpect = () => {
10
+ try {
11
+ return expectLib = require('expect');
12
+ }
13
+ catch (err) {
14
+ return console.error('Failed to load expect package. Make sure it has been installed: npm i expect');
15
+ }
16
+ };
17
+ exports.loadExpect = loadExpect;
18
+ const addMatchers = () => {
19
+ if (global.expect === undefined) {
20
+ if (!exports.loadExpect()) {
21
+ return;
22
+ }
23
+ global.expect = expectLib;
24
+ }
25
+ else {
26
+ expectLib = global.expect;
27
+ }
28
+ if (!global.expect.extend && !exports.isJasmine()) {
29
+ if (!exports.loadExpect()) {
30
+ return;
31
+ }
32
+ global.expectWdio = expectLib;
33
+ console.warn('Warning! Unsupported expect lib is used.\n' +
34
+ "Only Jasmine >= 3.3.0 and Jest's expect are supported.\n" +
35
+ "expect-webdriverio is assigned to global.expectWdio");
36
+ }
37
+ require('./options').setDefaultOptions;
38
+ const matchers = require('./matchers').default;
39
+ if (expectLib.extend) {
40
+ return expectLib.extend({ ...matchers });
41
+ }
42
+ expectLib = global.jasmine;
43
+ return expectLib.getEnv().beforeAll(function addExpectWebdriverIOMatchers() {
44
+ expectLib.addMatchers({ ...matchers });
45
+ expectLib.addAsyncMatchers({ ...matchers });
46
+ });
47
+ };
48
+ exports.addMatchers = addMatchers;
package/lib/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setOptions = void 0;
4
+ const addMatchers_1 = require("./addMatchers");
5
+ addMatchers_1.addMatchers();
6
+ exports.setOptions = require('./options').setDefaultOptions;
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isImmutableUnorderedSet = exports.isImmutableUnorderedKeyed = exports.hasProperty = exports.isUndefined = exports.fnNameFor = exports.isA = exports.equals = void 0;
4
+ function equals(a, b, customTesters, strictCheck) {
5
+ customTesters = customTesters || [];
6
+ return eq(a, b, [], [], customTesters, strictCheck ? hasKey : hasDefinedKey);
7
+ }
8
+ exports.equals = equals;
9
+ const functionToString = Function.prototype.toString;
10
+ function isAsymmetric(obj) {
11
+ return !!obj && isA('Function', obj.asymmetricMatch);
12
+ }
13
+ function asymmetricMatch(a, b) {
14
+ var asymmetricA = isAsymmetric(a), asymmetricB = isAsymmetric(b);
15
+ if (asymmetricA && asymmetricB) {
16
+ return undefined;
17
+ }
18
+ if (asymmetricA) {
19
+ return a.asymmetricMatch(b);
20
+ }
21
+ if (asymmetricB) {
22
+ return b.asymmetricMatch(a);
23
+ }
24
+ }
25
+ function eq(a, b, aStack, bStack, customTesters, hasKey) {
26
+ var result = true;
27
+ var asymmetricResult = asymmetricMatch(a, b);
28
+ if (asymmetricResult !== undefined) {
29
+ return asymmetricResult;
30
+ }
31
+ for (var i = 0; i < customTesters.length; i++) {
32
+ var customTesterResult = customTesters[i](a, b);
33
+ if (customTesterResult !== undefined) {
34
+ return customTesterResult;
35
+ }
36
+ }
37
+ if (a instanceof Error && b instanceof Error) {
38
+ return a.message == b.message;
39
+ }
40
+ if (Object.is(a, b)) {
41
+ return true;
42
+ }
43
+ if (a === null || b === null) {
44
+ return a === b;
45
+ }
46
+ var className = Object.prototype.toString.call(a);
47
+ if (className != Object.prototype.toString.call(b)) {
48
+ return false;
49
+ }
50
+ switch (className) {
51
+ case '[object Boolean]':
52
+ case '[object String]':
53
+ case '[object Number]':
54
+ if (typeof a !== typeof b) {
55
+ return false;
56
+ }
57
+ else if (typeof a !== 'object' && typeof b !== 'object') {
58
+ return Object.is(a, b);
59
+ }
60
+ else {
61
+ return Object.is(a.valueOf(), b.valueOf());
62
+ }
63
+ case '[object Date]':
64
+ return +a == +b;
65
+ case '[object RegExp]':
66
+ return a.source === b.source && a.flags === b.flags;
67
+ }
68
+ if (typeof a !== 'object' || typeof b !== 'object') {
69
+ return false;
70
+ }
71
+ if (isDomNode(a) && isDomNode(b)) {
72
+ return a.isEqualNode(b);
73
+ }
74
+ var length = aStack.length;
75
+ while (length--) {
76
+ if (aStack[length] === a) {
77
+ return bStack[length] === b;
78
+ }
79
+ else if (bStack[length] === b) {
80
+ return false;
81
+ }
82
+ }
83
+ aStack.push(a);
84
+ bStack.push(b);
85
+ var size = 0;
86
+ if (className == '[object Array]') {
87
+ size = a.length;
88
+ if (size !== b.length) {
89
+ return false;
90
+ }
91
+ while (size--) {
92
+ result = eq(a[size], b[size], aStack, bStack, customTesters, hasKey);
93
+ if (!result) {
94
+ return false;
95
+ }
96
+ }
97
+ }
98
+ var aKeys = keys(a, className == '[object Array]', hasKey), key;
99
+ size = aKeys.length;
100
+ if (keys(b, className == '[object Array]', hasKey).length !== size) {
101
+ return false;
102
+ }
103
+ while (size--) {
104
+ key = aKeys[size];
105
+ result =
106
+ hasKey(b, key) &&
107
+ eq(a[key], b[key], aStack, bStack, customTesters, hasKey);
108
+ if (!result) {
109
+ return false;
110
+ }
111
+ }
112
+ aStack.pop();
113
+ bStack.pop();
114
+ return result;
115
+ }
116
+ function keys(obj, isArray, hasKey) {
117
+ var allKeys = (function (o) {
118
+ var keys = [];
119
+ for (var key in o) {
120
+ if (hasKey(o, key)) {
121
+ keys.push(key);
122
+ }
123
+ }
124
+ return keys.concat(Object.getOwnPropertySymbols(o).filter(symbol => Object.getOwnPropertyDescriptor(o, symbol)
125
+ .enumerable));
126
+ })(obj);
127
+ if (!isArray) {
128
+ return allKeys;
129
+ }
130
+ var extraKeys = [];
131
+ if (allKeys.length === 0) {
132
+ return allKeys;
133
+ }
134
+ for (var x = 0; x < allKeys.length; x++) {
135
+ if (typeof allKeys[x] === 'symbol' || !allKeys[x].match(/^[0-9]+$/)) {
136
+ extraKeys.push(allKeys[x]);
137
+ }
138
+ }
139
+ return extraKeys;
140
+ }
141
+ function hasDefinedKey(obj, key) {
142
+ return hasKey(obj, key) && obj[key] !== undefined;
143
+ }
144
+ function hasKey(obj, key) {
145
+ return Object.prototype.hasOwnProperty.call(obj, key);
146
+ }
147
+ function isA(typeName, value) {
148
+ return Object.prototype.toString.apply(value) === '[object ' + typeName + ']';
149
+ }
150
+ exports.isA = isA;
151
+ function isDomNode(obj) {
152
+ return (obj !== null &&
153
+ typeof obj === 'object' &&
154
+ typeof obj.nodeType === 'number' &&
155
+ typeof obj.nodeName === 'string' &&
156
+ typeof obj.isEqualNode === 'function');
157
+ }
158
+ function fnNameFor(func) {
159
+ if (func.name) {
160
+ return func.name;
161
+ }
162
+ const matches = functionToString
163
+ .call(func)
164
+ .match(/^(?:async)?\s*function\s*\*?\s*([\w$]+)\s*\(/);
165
+ return matches ? matches[1] : '<anonymous>';
166
+ }
167
+ exports.fnNameFor = fnNameFor;
168
+ function isUndefined(obj) {
169
+ return obj === void 0;
170
+ }
171
+ exports.isUndefined = isUndefined;
172
+ function getPrototype(obj) {
173
+ if (Object.getPrototypeOf) {
174
+ return Object.getPrototypeOf(obj);
175
+ }
176
+ if (obj.constructor.prototype == obj) {
177
+ return null;
178
+ }
179
+ return obj.constructor.prototype;
180
+ }
181
+ function hasProperty(obj, property) {
182
+ if (!obj) {
183
+ return false;
184
+ }
185
+ if (Object.prototype.hasOwnProperty.call(obj, property)) {
186
+ return true;
187
+ }
188
+ return hasProperty(getPrototype(obj), property);
189
+ }
190
+ exports.hasProperty = hasProperty;
191
+ const IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
192
+ const IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
193
+ const IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
194
+ function isImmutableUnorderedKeyed(maybeKeyed) {
195
+ return !!(maybeKeyed &&
196
+ maybeKeyed[IS_KEYED_SENTINEL] &&
197
+ !maybeKeyed[IS_ORDERED_SENTINEL]);
198
+ }
199
+ exports.isImmutableUnorderedKeyed = isImmutableUnorderedKeyed;
200
+ function isImmutableUnorderedSet(maybeSet) {
201
+ return !!(maybeSet &&
202
+ maybeSet[IS_SET_SENTINEL] &&
203
+ !maybeSet[IS_ORDERED_SENTINEL]);
204
+ }
205
+ exports.isImmutableUnorderedSet = isImmutableUnorderedSet;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toHaveTitle = exports.toHaveTitleFn = void 0;
4
+ const expectAdapter_1 = require("../../util/expectAdapter");
5
+ const utils_1 = require("../../utils");
6
+ function toHaveTitleFn(browser, title, options = {}) {
7
+ const isNot = this.isNot;
8
+ const { expectation = 'title', verb = 'have' } = this;
9
+ return browser.call(async () => {
10
+ let actual;
11
+ const pass = await utils_1.waitUntil(async () => {
12
+ actual = await browser.getTitle();
13
+ return utils_1.compareText(actual, title, options).result;
14
+ }, isNot, options);
15
+ const message = utils_1.enhanceError('window', title, actual, this, verb, expectation, '', options);
16
+ return {
17
+ pass,
18
+ message: () => message
19
+ };
20
+ });
21
+ }
22
+ exports.toHaveTitleFn = toHaveTitleFn;
23
+ function toHaveTitle(...args) {
24
+ return expectAdapter_1.runExpect.call(this, toHaveTitleFn, args);
25
+ }
26
+ exports.toHaveTitle = toHaveTitle;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toHaveTitleContaining = void 0;
4
+ const expectAdapter_1 = require("../../util/expectAdapter");
5
+ const toHaveTitle_1 = require("./toHaveTitle");
6
+ function toHaveTitleContainingFn(browser, title, options = {}) {
7
+ return toHaveTitle_1.toHaveTitleFn.call(this, browser, title, {
8
+ ...options,
9
+ containing: true
10
+ });
11
+ }
12
+ function toHaveTitleContaining(...args) {
13
+ return expectAdapter_1.runExpect.call(this, toHaveTitleContainingFn, args);
14
+ }
15
+ exports.toHaveTitleContaining = toHaveTitleContaining;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toHaveUrl = exports.toHaveUrlFn = void 0;
4
+ const expectAdapter_1 = require("../../util/expectAdapter");
5
+ const utils_1 = require("../../utils");
6
+ function toHaveUrlFn(browser, url, options = {}) {
7
+ const isNot = this.isNot;
8
+ const { expectation = 'url', verb = 'have' } = this;
9
+ return browser.call(async () => {
10
+ let actual;
11
+ const pass = await utils_1.waitUntil(async () => {
12
+ actual = await browser.getUrl();
13
+ return utils_1.compareText(actual, url, options).result;
14
+ }, isNot, options);
15
+ const message = utils_1.enhanceError('window', url, actual, this, verb, expectation, '', options);
16
+ return {
17
+ pass,
18
+ message: () => message
19
+ };
20
+ });
21
+ }
22
+ exports.toHaveUrlFn = toHaveUrlFn;
23
+ function toHaveUrl(...args) {
24
+ return expectAdapter_1.runExpect.call(this, toHaveUrlFn, args);
25
+ }
26
+ exports.toHaveUrl = toHaveUrl;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toHaveUrlContaining = void 0;
4
+ const expectAdapter_1 = require("../../util/expectAdapter");
5
+ const toHaveUrl_1 = require("./toHaveUrl");
6
+ function toHaveUrlContainingFn(browser, url, options = {}) {
7
+ return toHaveUrl_1.toHaveUrlFn.call(this, browser, url, {
8
+ ...options,
9
+ containing: true
10
+ });
11
+ }
12
+ function toHaveUrlContaining(...args) {
13
+ return expectAdapter_1.runExpect.call(this, toHaveUrlContainingFn, args);
14
+ }
15
+ exports.toHaveUrlContaining = toHaveUrlContaining;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toBeClickable = void 0;
4
+ const utils_1 = require("../../utils");
5
+ const expectAdapter_1 = require("../../util/expectAdapter");
6
+ function toBeClickableFn(received, options = {}) {
7
+ this.expectation = this.expectation || 'clickable';
8
+ return browser.call(async () => {
9
+ const result = await utils_1.executeCommandBe.call(this, received, async (el) => {
10
+ try {
11
+ return el.isClickable();
12
+ }
13
+ catch (_a) {
14
+ return false;
15
+ }
16
+ }, options);
17
+ return result;
18
+ });
19
+ }
20
+ function toBeClickable(...args) {
21
+ return expectAdapter_1.runExpect.call(this, toBeClickableFn, args);
22
+ }
23
+ exports.toBeClickable = toBeClickable;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toBeDisabled = void 0;
4
+ const utils_1 = require("../../utils");
5
+ const expectAdapter_1 = require("../../util/expectAdapter");
6
+ function toBeDisabledFn(received, options = {}) {
7
+ this.expectation = this.expectation || 'disabled';
8
+ return browser.call(async () => {
9
+ const result = await utils_1.executeCommandBe.call(this, received, async (el) => !await el.isEnabled(), options);
10
+ return result;
11
+ });
12
+ }
13
+ function toBeDisabled(...args) {
14
+ return expectAdapter_1.runExpect.call(this, toBeDisabledFn, args);
15
+ }
16
+ exports.toBeDisabled = toBeDisabled;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toBeVisible = exports.toBeDisplayed = void 0;
4
+ const utils_1 = require("../../utils");
5
+ const expectAdapter_1 = require("../../util/expectAdapter");
6
+ function toBeDisplayedFn(received, options = {}) {
7
+ this.expectation = this.expectation || 'displayed';
8
+ return browser.call(async () => {
9
+ const result = await utils_1.executeCommandBe.call(this, received, async (el) => {
10
+ try {
11
+ return el.isDisplayed();
12
+ }
13
+ catch (_a) {
14
+ return false;
15
+ }
16
+ }, options);
17
+ return result;
18
+ });
19
+ }
20
+ function toBeDisplayed(...args) {
21
+ return expectAdapter_1.runExpect.call(this, toBeDisplayedFn, args);
22
+ }
23
+ exports.toBeDisplayed = toBeDisplayed;
24
+ function toBeVisible(el, options) {
25
+ return utils_1.aliasFn.call(this, toBeDisplayed, { expectation: 'visible' }, el, options);
26
+ }
27
+ exports.toBeVisible = toBeVisible;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toBeVisibleInViewport = exports.toBeDisplayedInViewport = void 0;
4
+ const utils_1 = require("../../utils");
5
+ const expectAdapter_1 = require("../../util/expectAdapter");
6
+ function toBeDisplayedInViewportFn(received, options = {}) {
7
+ this.expectation = this.expectation || 'displayed in viewport';
8
+ return browser.call(async () => {
9
+ const result = await utils_1.executeCommandBe.call(this, received, async (el) => {
10
+ try {
11
+ return el.isDisplayedInViewport();
12
+ }
13
+ catch (_a) {
14
+ return false;
15
+ }
16
+ }, options);
17
+ return result;
18
+ });
19
+ }
20
+ function toBeDisplayedInViewport(...args) {
21
+ return expectAdapter_1.runExpect.call(this, toBeDisplayedInViewportFn, args);
22
+ }
23
+ exports.toBeDisplayedInViewport = toBeDisplayedInViewport;
24
+ function toBeVisibleInViewport(el, options) {
25
+ return utils_1.aliasFn.call(this, toBeDisplayedInViewport, { expectation: 'visible in viewport' }, el, options);
26
+ }
27
+ exports.toBeVisibleInViewport = toBeVisibleInViewport;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toBeEnabled = void 0;
4
+ const utils_1 = require("../../utils");
5
+ const expectAdapter_1 = require("../../util/expectAdapter");
6
+ function toBeEnabledFn(received, options = {}) {
7
+ this.expectation = this.expectation || 'enabled';
8
+ return browser.call(async () => {
9
+ const result = await utils_1.executeCommandBe.call(this, received, el => el.isEnabled(), options);
10
+ return result;
11
+ });
12
+ }
13
+ function toBeEnabled(...args) {
14
+ return expectAdapter_1.runExpect.call(this, toBeEnabledFn, args);
15
+ }
16
+ exports.toBeEnabled = toBeEnabled;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toBePresent = exports.toBeExisting = exports.toExist = void 0;
4
+ const utils_1 = require("../../utils");
5
+ const expectAdapter_1 = require("../../util/expectAdapter");
6
+ function toExistFn(received, options = {}) {
7
+ this.expectation = this.expectation || 'exist';
8
+ this.verb = this.verb || '';
9
+ return browser.call(async () => {
10
+ const result = await utils_1.executeCommandBe.call(this, received, async (el) => {
11
+ try {
12
+ return el.isExisting();
13
+ }
14
+ catch (_a) {
15
+ return false;
16
+ }
17
+ }, options);
18
+ return result;
19
+ });
20
+ }
21
+ function toExist(...args) {
22
+ return expectAdapter_1.runExpect.call(this, toExistFn, args);
23
+ }
24
+ exports.toExist = toExist;
25
+ function toBeExisting(el, options) {
26
+ return utils_1.aliasFn.call(this, toExist, { verb: 'be', expectation: 'existing' }, el, options);
27
+ }
28
+ exports.toBeExisting = toBeExisting;
29
+ function toBePresent(el, options) {
30
+ return utils_1.aliasFn.call(this, toExist, { verb: 'be', expectation: 'present' }, el, options);
31
+ }
32
+ exports.toBePresent = toBePresent;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toBeFocused = void 0;
4
+ const utils_1 = require("../../utils");
5
+ const expectAdapter_1 = require("../../util/expectAdapter");
6
+ function toBeFocusedFn(received, options = {}) {
7
+ this.expectation = this.expectation || 'focused';
8
+ return browser.call(async () => {
9
+ const result = await utils_1.executeCommandBe.call(this, received, el => el.isFocused(), options);
10
+ return result;
11
+ });
12
+ }
13
+ function toBeFocused(...args) {
14
+ return expectAdapter_1.runExpect.call(this, toBeFocusedFn, args);
15
+ }
16
+ exports.toBeFocused = toBeFocused;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toBeChecked = exports.toBeSelected = void 0;
4
+ const utils_1 = require("../../utils");
5
+ const expectAdapter_1 = require("../../util/expectAdapter");
6
+ function toBeSelectedFn(received, options = {}) {
7
+ this.expectation = this.expectation || 'selected';
8
+ return browser.call(async () => {
9
+ const result = await utils_1.executeCommandBe.call(this, received, el => el.isSelected(), options);
10
+ return result;
11
+ });
12
+ }
13
+ function toBeSelected(...args) {
14
+ return expectAdapter_1.runExpect.call(this, toBeSelectedFn, args);
15
+ }
16
+ exports.toBeSelected = toBeSelected;
17
+ function toBeChecked(el, options) {
18
+ const context = expectAdapter_1.getContext(this);
19
+ context.expectation = 'checked';
20
+ return toBeSelected.call(context, el, options);
21
+ }
22
+ exports.toBeChecked = toBeChecked;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toHaveAttr = exports.toHaveAttribute = exports.toHaveAttributeFn = void 0;
4
+ const utils_1 = require("../../utils");
5
+ const expectAdapter_1 = require("../../util/expectAdapter");
6
+ async function condition(el, attribute, value, options) {
7
+ const attr = await el.getAttribute(attribute);
8
+ if (typeof attr !== 'string') {
9
+ return { result: false, value: attr };
10
+ }
11
+ if (typeof value !== 'string') {
12
+ return { result: true, value: attr };
13
+ }
14
+ return utils_1.compareText(attr, value, options);
15
+ }
16
+ function toHaveAttributeFn(received, attribute, value, options = {}) {
17
+ const isNot = this.isNot;
18
+ const { expectation = 'attribute', verb = 'have' } = this;
19
+ return browser.call(async () => {
20
+ let el = await received;
21
+ let attr;
22
+ const pass = await utils_1.waitUntil(async () => {
23
+ const result = await utils_1.executeCommand.call(this, el, condition, options, [attribute, value, options]);
24
+ el = result.el;
25
+ attr = result.values;
26
+ return result.success;
27
+ }, isNot, options);
28
+ utils_1.updateElementsArray(pass, received, el);
29
+ let message;
30
+ if (typeof value === 'string') {
31
+ const expected = utils_1.wrapExpectedWithArray(el, attr, value);
32
+ message = utils_1.enhanceError(el, expected, attr, this, verb, expectation, attribute, options);
33
+ }
34
+ else {
35
+ message = utils_1.enhanceError(el, !isNot, pass, this, verb, expectation, attribute, options);
36
+ }
37
+ return {
38
+ pass,
39
+ message: () => message
40
+ };
41
+ });
42
+ }
43
+ exports.toHaveAttributeFn = toHaveAttributeFn;
44
+ function toHaveAttribute(...args) {
45
+ return expectAdapter_1.runExpect.call(this, toHaveAttributeFn, args);
46
+ }
47
+ exports.toHaveAttribute = toHaveAttribute;
48
+ exports.toHaveAttr = toHaveAttribute;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toHaveAttrContaining = exports.toHaveAttributeContaining = void 0;
4
+ const expectAdapter_1 = require("../../util/expectAdapter");
5
+ const toHaveAttribute_1 = require("./toHaveAttribute");
6
+ function toHaveAttributeContainingFn(el, attribute, value, options = {}) {
7
+ return toHaveAttribute_1.toHaveAttributeFn.call(this, el, attribute, value, {
8
+ ...options,
9
+ containing: true
10
+ });
11
+ }
12
+ function toHaveAttributeContaining(...args) {
13
+ return expectAdapter_1.runExpect.call(this, toHaveAttributeContainingFn, args);
14
+ }
15
+ exports.toHaveAttributeContaining = toHaveAttributeContaining;
16
+ exports.toHaveAttrContaining = toHaveAttributeContaining;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toHaveChildren = void 0;
4
+ const utils_1 = require("../../utils");
5
+ const expectAdapter_1 = require("../../util/expectAdapter");
6
+ async function condition(el, gte, lte, eq) {
7
+ const children = await el.$$('./*');
8
+ return {
9
+ result: utils_1.compareNumbers(children.length, gte, lte, eq),
10
+ value: children.length
11
+ };
12
+ }
13
+ function toHaveChildrenFn(received, size, options = {}) {
14
+ const isNot = this.isNot;
15
+ const { expectation = 'children', verb = 'have' } = this;
16
+ if (typeof size === 'number') {
17
+ options.eq = size;
18
+ }
19
+ else if (typeof size === 'object') {
20
+ options = { ...options, ...size };
21
+ }
22
+ const eq = options.eq;
23
+ const gte = options.gte || 1;
24
+ const lte = options.lte || 0;
25
+ return browser.call(async () => {
26
+ let el = await received;
27
+ let children;
28
+ const pass = await utils_1.waitUntil(async () => {
29
+ const result = await utils_1.executeCommand.call(this, el, condition, options, [gte, lte, eq]);
30
+ el = result.el;
31
+ children = result.values;
32
+ return result.success;
33
+ }, isNot, options);
34
+ utils_1.updateElementsArray(pass, received, el);
35
+ const error = utils_1.numberError(gte, lte, eq);
36
+ const expected = utils_1.wrapExpectedWithArray(el, children, error);
37
+ const message = utils_1.enhanceError(el, expected, children, this, verb, expectation, '', options);
38
+ return {
39
+ pass,
40
+ message: () => message
41
+ };
42
+ });
43
+ }
44
+ function toHaveChildren(...args) {
45
+ return expectAdapter_1.runExpect.call(this, toHaveChildrenFn, args);
46
+ }
47
+ exports.toHaveChildren = toHaveChildren;