expect-webdriverio 3.4.0 → 4.0.0-alpha.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.
- package/jest.d.ts +1 -1
- package/lib/constants.js +4 -0
- package/lib/index.js +15 -6
- package/lib/jasmineUtils.js +7 -17
- package/lib/matchers/browser/toHaveTitle.js +5 -14
- package/lib/matchers/browser/toHaveTitleContaining.js +3 -11
- package/lib/matchers/browser/toHaveUrl.js +5 -14
- package/lib/matchers/browser/toHaveUrlContaining.js +3 -11
- package/lib/matchers/element/toBeClickable.js +5 -12
- package/lib/matchers/element/toBeDisabled.js +4 -11
- package/lib/matchers/element/toBeDisplayed.js +5 -12
- package/lib/matchers/element/toBeDisplayedInViewport.js +5 -12
- package/lib/matchers/element/toBeEnabled.js +4 -11
- package/lib/matchers/element/toBeExisting.js +9 -18
- package/lib/matchers/element/toBeFocused.js +4 -11
- package/lib/matchers/element/toBeSelected.js +7 -16
- package/lib/matchers/element/toHaveAttribute.js +18 -24
- package/lib/matchers/element/toHaveAttributeContaining.js +4 -12
- package/lib/matchers/element/toHaveChildren.js +12 -19
- package/lib/matchers/element/{toHaveElementClass.js → toHaveClass.js} +10 -19
- package/lib/matchers/element/toHaveClassContaining.js +10 -0
- package/lib/matchers/element/toHaveElementProperty.js +10 -18
- package/lib/matchers/element/toHaveHref.js +4 -13
- package/lib/matchers/element/toHaveHrefContaining.js +4 -12
- package/lib/matchers/element/toHaveId.js +3 -12
- package/lib/matchers/element/toHaveStyle.js +8 -16
- package/lib/matchers/element/toHaveText.js +9 -17
- package/lib/matchers/element/toHaveTextContaining.js +3 -11
- package/lib/matchers/element/toHaveValue.js +3 -12
- package/lib/matchers/element/toHaveValueContaining.js +3 -11
- package/lib/matchers/elements/toBeElementsArrayOfSize.js +10 -17
- package/lib/matchers/mock/toBeRequested.js +3 -11
- package/lib/matchers/mock/toBeRequestedTimes.js +8 -16
- package/lib/matchers/mock/toBeRequestedWith.js +13 -19
- package/lib/matchers.js +62 -35
- package/lib/types.js +1 -0
- package/lib/util/elementsUtil.js +2 -7
- package/lib/util/executeCommand.js +3 -7
- package/lib/util/formatMessage.js +17 -26
- package/lib/util/refetchElements.js +2 -8
- package/lib/utils.js +15 -32
- package/package.json +49 -42
- package/types/jest-global.d.ts +1 -1
- package/types/standalone.d.ts +1 -1
- package/jasmine.d.ts +0 -6
- package/lib/addMatchers.js +0 -48
- package/lib/matchers/element/toHaveElementClassContaining.js +0 -20
- package/lib/matchers/mock/toBeRequestedWithResponse.js +0 -13
- package/lib/options.js +0 -33
- package/lib/util/expectAdapter.js +0 -41
- package/types/standalone-global.d.ts +0 -12
package/jest.d.ts
CHANGED
package/lib/constants.js
ADDED
package/lib/index.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
(
|
|
6
|
-
|
|
1
|
+
import expectLib from 'expect';
|
|
2
|
+
import matchers from './matchers.js';
|
|
3
|
+
import { DEFAULT_OPTIONS } from './constants.js';
|
|
4
|
+
export const getConfig = () => DEFAULT_OPTIONS;
|
|
5
|
+
export const setDefaultOptions = (options = {}) => {
|
|
6
|
+
Object.entries(options).forEach(([key, value]) => {
|
|
7
|
+
if (key in DEFAULT_OPTIONS) {
|
|
8
|
+
DEFAULT_OPTIONS[key] = value;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
export const expect = async () => {
|
|
13
|
+
return expectLib.extend({ ...matchers });
|
|
14
|
+
};
|
|
15
|
+
export const setOptions = setDefaultOptions;
|
package/lib/jasmineUtils.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
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) {
|
|
1
|
+
export function equals(a, b, customTesters, strictCheck) {
|
|
5
2
|
customTesters = customTesters || [];
|
|
6
3
|
return eq(a, b, [], [], customTesters, strictCheck ? hasKey : hasDefinedKey);
|
|
7
4
|
}
|
|
8
|
-
exports.equals = equals;
|
|
9
5
|
const functionToString = Function.prototype.toString;
|
|
10
6
|
function isAsymmetric(obj) {
|
|
11
7
|
return !!obj && isA('Function', obj.asymmetricMatch);
|
|
@@ -144,10 +140,9 @@ function hasDefinedKey(obj, key) {
|
|
|
144
140
|
function hasKey(obj, key) {
|
|
145
141
|
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
146
142
|
}
|
|
147
|
-
function isA(typeName, value) {
|
|
143
|
+
export function isA(typeName, value) {
|
|
148
144
|
return Object.prototype.toString.apply(value) === '[object ' + typeName + ']';
|
|
149
145
|
}
|
|
150
|
-
exports.isA = isA;
|
|
151
146
|
function isDomNode(obj) {
|
|
152
147
|
return (obj !== null &&
|
|
153
148
|
typeof obj === 'object' &&
|
|
@@ -155,7 +150,7 @@ function isDomNode(obj) {
|
|
|
155
150
|
typeof obj.nodeName === 'string' &&
|
|
156
151
|
typeof obj.isEqualNode === 'function');
|
|
157
152
|
}
|
|
158
|
-
function fnNameFor(func) {
|
|
153
|
+
export function fnNameFor(func) {
|
|
159
154
|
if (func.name) {
|
|
160
155
|
return func.name;
|
|
161
156
|
}
|
|
@@ -164,11 +159,9 @@ function fnNameFor(func) {
|
|
|
164
159
|
.match(/^(?:async)?\s*function\s*\*?\s*([\w$]+)\s*\(/);
|
|
165
160
|
return matches ? matches[1] : '<anonymous>';
|
|
166
161
|
}
|
|
167
|
-
|
|
168
|
-
function isUndefined(obj) {
|
|
162
|
+
export function isUndefined(obj) {
|
|
169
163
|
return obj === void 0;
|
|
170
164
|
}
|
|
171
|
-
exports.isUndefined = isUndefined;
|
|
172
165
|
function getPrototype(obj) {
|
|
173
166
|
if (Object.getPrototypeOf) {
|
|
174
167
|
return Object.getPrototypeOf(obj);
|
|
@@ -178,7 +171,7 @@ function getPrototype(obj) {
|
|
|
178
171
|
}
|
|
179
172
|
return obj.constructor.prototype;
|
|
180
173
|
}
|
|
181
|
-
function hasProperty(obj, property) {
|
|
174
|
+
export function hasProperty(obj, property) {
|
|
182
175
|
if (!obj) {
|
|
183
176
|
return false;
|
|
184
177
|
}
|
|
@@ -187,19 +180,16 @@ function hasProperty(obj, property) {
|
|
|
187
180
|
}
|
|
188
181
|
return hasProperty(getPrototype(obj), property);
|
|
189
182
|
}
|
|
190
|
-
exports.hasProperty = hasProperty;
|
|
191
183
|
const IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
|
|
192
184
|
const IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
|
|
193
185
|
const IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
|
|
194
|
-
function isImmutableUnorderedKeyed(maybeKeyed) {
|
|
186
|
+
export function isImmutableUnorderedKeyed(maybeKeyed) {
|
|
195
187
|
return !!(maybeKeyed &&
|
|
196
188
|
maybeKeyed[IS_KEYED_SENTINEL] &&
|
|
197
189
|
!maybeKeyed[IS_ORDERED_SENTINEL]);
|
|
198
190
|
}
|
|
199
|
-
|
|
200
|
-
function isImmutableUnorderedSet(maybeSet) {
|
|
191
|
+
export function isImmutableUnorderedSet(maybeSet) {
|
|
201
192
|
return !!(maybeSet &&
|
|
202
193
|
maybeSet[IS_SET_SENTINEL] &&
|
|
203
194
|
!maybeSet[IS_ORDERED_SENTINEL]);
|
|
204
195
|
}
|
|
205
|
-
exports.isImmutableUnorderedSet = isImmutableUnorderedSet;
|
|
@@ -1,26 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 = {}) {
|
|
1
|
+
import { waitUntil, enhanceError, compareText } from '../../utils';
|
|
2
|
+
export function toHaveTitle(browser, title, options = {}) {
|
|
7
3
|
const isNot = this.isNot;
|
|
8
4
|
const { expectation = 'title', verb = 'have' } = this;
|
|
9
5
|
return browser.call(async () => {
|
|
10
6
|
let actual;
|
|
11
|
-
const pass = await
|
|
7
|
+
const pass = await waitUntil(async () => {
|
|
12
8
|
actual = await browser.getTitle();
|
|
13
|
-
return
|
|
9
|
+
return compareText(actual, title, options).result;
|
|
14
10
|
}, isNot, options);
|
|
15
|
-
const message =
|
|
11
|
+
const message = enhanceError('window', title, actual, this, verb, expectation, '', options);
|
|
16
12
|
return {
|
|
17
13
|
pass,
|
|
18
14
|
message: () => message
|
|
19
15
|
};
|
|
20
16
|
});
|
|
21
17
|
}
|
|
22
|
-
exports.toHaveTitleFn = toHaveTitleFn;
|
|
23
|
-
function toHaveTitle(...args) {
|
|
24
|
-
return expectAdapter_1.runExpect.call(this || {}, toHaveTitleFn, args);
|
|
25
|
-
}
|
|
26
|
-
exports.toHaveTitle = toHaveTitle;
|
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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, {
|
|
1
|
+
import { toHaveTitle } from './toHaveTitle';
|
|
2
|
+
export function toHaveTitleContaining(browser, title, options = {}) {
|
|
3
|
+
return toHaveTitle.call(this, browser, title, {
|
|
8
4
|
...options,
|
|
9
5
|
containing: true
|
|
10
6
|
});
|
|
11
7
|
}
|
|
12
|
-
function toHaveTitleContaining(...args) {
|
|
13
|
-
return expectAdapter_1.runExpect.call(this || {}, toHaveTitleContainingFn, args);
|
|
14
|
-
}
|
|
15
|
-
exports.toHaveTitleContaining = toHaveTitleContaining;
|
|
@@ -1,26 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 = {}) {
|
|
1
|
+
import { waitUntil, enhanceError, compareText } from '../../utils';
|
|
2
|
+
export function toHaveUrl(browser, url, options = {}) {
|
|
7
3
|
const isNot = this.isNot;
|
|
8
4
|
const { expectation = 'url', verb = 'have' } = this;
|
|
9
5
|
return browser.call(async () => {
|
|
10
6
|
let actual;
|
|
11
|
-
const pass = await
|
|
7
|
+
const pass = await waitUntil(async () => {
|
|
12
8
|
actual = await browser.getUrl();
|
|
13
|
-
return
|
|
9
|
+
return compareText(actual, url, options).result;
|
|
14
10
|
}, isNot, options);
|
|
15
|
-
const message =
|
|
11
|
+
const message = enhanceError('window', url, actual, this, verb, expectation, '', options);
|
|
16
12
|
return {
|
|
17
13
|
pass,
|
|
18
14
|
message: () => message
|
|
19
15
|
};
|
|
20
16
|
});
|
|
21
17
|
}
|
|
22
|
-
exports.toHaveUrlFn = toHaveUrlFn;
|
|
23
|
-
function toHaveUrl(...args) {
|
|
24
|
-
return expectAdapter_1.runExpect.call(this || {}, toHaveUrlFn, args);
|
|
25
|
-
}
|
|
26
|
-
exports.toHaveUrl = toHaveUrl;
|
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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, {
|
|
1
|
+
import { toHaveUrl } from './toHaveUrl';
|
|
2
|
+
export function toHaveUrlContaining(browser, url, options = {}) {
|
|
3
|
+
return toHaveUrl.call(this, browser, url, {
|
|
8
4
|
...options,
|
|
9
5
|
containing: true
|
|
10
6
|
});
|
|
11
7
|
}
|
|
12
|
-
function toHaveUrlContaining(...args) {
|
|
13
|
-
return expectAdapter_1.runExpect.call(this || {}, toHaveUrlContainingFn, args);
|
|
14
|
-
}
|
|
15
|
-
exports.toHaveUrlContaining = toHaveUrlContaining;
|
|
@@ -1,23 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const utils_1 = require("../../utils");
|
|
5
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
function toBeClickableFn(received, options = {}) {
|
|
1
|
+
import { browser } from '@wdio/globals';
|
|
2
|
+
import { executeCommandBe } from '../../utils';
|
|
3
|
+
export function toBeClickable(received, options = {}) {
|
|
7
4
|
this.expectation = this.expectation || 'clickable';
|
|
8
5
|
return browser.call(async () => {
|
|
9
|
-
const result = await
|
|
6
|
+
const result = await executeCommandBe.call(this, received, async (el) => {
|
|
10
7
|
try {
|
|
11
8
|
return el.isClickable();
|
|
12
9
|
}
|
|
13
|
-
catch
|
|
10
|
+
catch {
|
|
14
11
|
return false;
|
|
15
12
|
}
|
|
16
13
|
}, options);
|
|
17
14
|
return result;
|
|
18
15
|
});
|
|
19
16
|
}
|
|
20
|
-
function toBeClickable(...args) {
|
|
21
|
-
return expectAdapter_1.runExpect.call(this || {}, toBeClickableFn, args);
|
|
22
|
-
}
|
|
23
|
-
exports.toBeClickable = toBeClickable;
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const utils_1 = require("../../utils");
|
|
5
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
function toBeDisabledFn(received, options = {}) {
|
|
1
|
+
import { browser } from '@wdio/globals';
|
|
2
|
+
import { executeCommandBe } from '../../utils';
|
|
3
|
+
export function toBeDisabled(received, options = {}) {
|
|
7
4
|
this.expectation = this.expectation || 'disabled';
|
|
8
5
|
return browser.call(async () => {
|
|
9
|
-
const result = await
|
|
6
|
+
const result = await executeCommandBe.call(this, received, async (el) => !await el.isEnabled(), options);
|
|
10
7
|
return result;
|
|
11
8
|
});
|
|
12
9
|
}
|
|
13
|
-
function toBeDisabled(...args) {
|
|
14
|
-
return expectAdapter_1.runExpect.call(this || {}, toBeDisabledFn, args);
|
|
15
|
-
}
|
|
16
|
-
exports.toBeDisabled = toBeDisabled;
|
|
@@ -1,23 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const utils_1 = require("../../utils");
|
|
5
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
function toBeDisplayedFn(received, options = {}) {
|
|
1
|
+
import { browser } from '@wdio/globals';
|
|
2
|
+
import { executeCommandBe } from '../../utils';
|
|
3
|
+
export function toBeDisplayed(received, options = {}) {
|
|
7
4
|
this.expectation = this.expectation || 'displayed';
|
|
8
5
|
return browser.call(async () => {
|
|
9
|
-
const result = await
|
|
6
|
+
const result = await executeCommandBe.call(this, received, async (el) => {
|
|
10
7
|
try {
|
|
11
8
|
return el.isDisplayed();
|
|
12
9
|
}
|
|
13
|
-
catch
|
|
10
|
+
catch {
|
|
14
11
|
return false;
|
|
15
12
|
}
|
|
16
13
|
}, options);
|
|
17
14
|
return result;
|
|
18
15
|
});
|
|
19
16
|
}
|
|
20
|
-
function toBeDisplayed(...args) {
|
|
21
|
-
return expectAdapter_1.runExpect.call(this || {}, toBeDisplayedFn, args);
|
|
22
|
-
}
|
|
23
|
-
exports.toBeDisplayed = toBeDisplayed;
|
|
@@ -1,23 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const utils_1 = require("../../utils");
|
|
5
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
function toBeDisplayedInViewportFn(received, options = {}) {
|
|
1
|
+
import { browser } from '@wdio/globals';
|
|
2
|
+
import { executeCommandBe } from '../../utils';
|
|
3
|
+
export function toBeDisplayedInViewport(received, options = {}) {
|
|
7
4
|
this.expectation = this.expectation || 'displayed in viewport';
|
|
8
5
|
return browser.call(async () => {
|
|
9
|
-
const result = await
|
|
6
|
+
const result = await executeCommandBe.call(this, received, async (el) => {
|
|
10
7
|
try {
|
|
11
8
|
return el.isDisplayedInViewport();
|
|
12
9
|
}
|
|
13
|
-
catch
|
|
10
|
+
catch {
|
|
14
11
|
return false;
|
|
15
12
|
}
|
|
16
13
|
}, options);
|
|
17
14
|
return result;
|
|
18
15
|
});
|
|
19
16
|
}
|
|
20
|
-
function toBeDisplayedInViewport(...args) {
|
|
21
|
-
return expectAdapter_1.runExpect.call(this || {}, toBeDisplayedInViewportFn, args);
|
|
22
|
-
}
|
|
23
|
-
exports.toBeDisplayedInViewport = toBeDisplayedInViewport;
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const utils_1 = require("../../utils");
|
|
5
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
function toBeEnabledFn(received, options = {}) {
|
|
1
|
+
import { browser } from '@wdio/globals';
|
|
2
|
+
import { executeCommandBe } from '../../utils';
|
|
3
|
+
export function toBeEnabled(received, options = {}) {
|
|
7
4
|
this.expectation = this.expectation || 'enabled';
|
|
8
5
|
return browser.call(async () => {
|
|
9
|
-
const result = await
|
|
6
|
+
const result = await executeCommandBe.call(this, received, el => el.isEnabled(), options);
|
|
10
7
|
return result;
|
|
11
8
|
});
|
|
12
9
|
}
|
|
13
|
-
function toBeEnabled(...args) {
|
|
14
|
-
return expectAdapter_1.runExpect.call(this || {}, toBeEnabledFn, args);
|
|
15
|
-
}
|
|
16
|
-
exports.toBeEnabled = toBeEnabled;
|
|
@@ -1,32 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const utils_1 = require("../../utils");
|
|
5
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
function toExistFn(received, options = {}) {
|
|
1
|
+
import { browser } from '@wdio/globals';
|
|
2
|
+
import { executeCommandBe, aliasFn } from '../../utils';
|
|
3
|
+
export function toExist(received, options = {}) {
|
|
7
4
|
this.expectation = this.expectation || 'exist';
|
|
8
5
|
this.verb = this.verb || '';
|
|
9
6
|
return browser.call(async () => {
|
|
10
|
-
const result = await
|
|
7
|
+
const result = await executeCommandBe.call(this, received, async (el) => {
|
|
11
8
|
try {
|
|
12
9
|
return el.isExisting();
|
|
13
10
|
}
|
|
14
|
-
catch
|
|
11
|
+
catch {
|
|
15
12
|
return false;
|
|
16
13
|
}
|
|
17
14
|
}, options);
|
|
18
15
|
return result;
|
|
19
16
|
});
|
|
20
17
|
}
|
|
21
|
-
function
|
|
22
|
-
return
|
|
18
|
+
export function toBeExisting(el, options) {
|
|
19
|
+
return aliasFn.call(this, toExist, { verb: 'be', expectation: 'existing' }, el, options);
|
|
23
20
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return utils_1.aliasFn.call(this, toExist, { verb: 'be', expectation: 'existing' }, el, options);
|
|
21
|
+
export function toBePresent(el, options) {
|
|
22
|
+
return aliasFn.call(this, toExist, { verb: 'be', expectation: 'present' }, el, options);
|
|
27
23
|
}
|
|
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;
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const utils_1 = require("../../utils");
|
|
5
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
function toBeFocusedFn(received, options = {}) {
|
|
1
|
+
import { browser } from '@wdio/globals';
|
|
2
|
+
import { executeCommandBe } from '../../utils';
|
|
3
|
+
export function toBeFocused(received, options = {}) {
|
|
7
4
|
this.expectation = this.expectation || 'focused';
|
|
8
5
|
return browser.call(async () => {
|
|
9
|
-
const result = await
|
|
6
|
+
const result = await executeCommandBe.call(this, received, el => el.isFocused(), options);
|
|
10
7
|
return result;
|
|
11
8
|
});
|
|
12
9
|
}
|
|
13
|
-
function toBeFocused(...args) {
|
|
14
|
-
return expectAdapter_1.runExpect.call(this || {}, toBeFocusedFn, args);
|
|
15
|
-
}
|
|
16
|
-
exports.toBeFocused = toBeFocused;
|
|
@@ -1,22 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const utils_1 = require("../../utils");
|
|
5
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
function toBeSelectedFn(received, options = {}) {
|
|
1
|
+
import { browser } from '@wdio/globals';
|
|
2
|
+
import { executeCommandBe } from '../../utils';
|
|
3
|
+
export function toBeSelected(received, options = {}) {
|
|
7
4
|
this.expectation = this.expectation || 'selected';
|
|
8
5
|
return browser.call(async () => {
|
|
9
|
-
const result = await
|
|
6
|
+
const result = await executeCommandBe.call(this, received, el => el.isSelected(), options);
|
|
10
7
|
return result;
|
|
11
8
|
});
|
|
12
9
|
}
|
|
13
|
-
function
|
|
14
|
-
|
|
10
|
+
export function toBeChecked(el, options) {
|
|
11
|
+
this.expectation = 'checked';
|
|
12
|
+
return toBeSelected.call(this, el, options);
|
|
15
13
|
}
|
|
16
|
-
exports.toBeSelected = toBeSelected;
|
|
17
|
-
function toBeChecked(el, options) {
|
|
18
|
-
const context = (0, expectAdapter_1.getContext)(this);
|
|
19
|
-
context.expectation = 'checked';
|
|
20
|
-
return toBeSelected.call(context, el, options);
|
|
21
|
-
}
|
|
22
|
-
exports.toBeChecked = toBeChecked;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.toHaveAttr = exports.toHaveAttribute = exports.toHaveAttributeFn = exports.toHaveAttributeAndValueFn = void 0;
|
|
4
|
-
const utils_1 = require("../../utils");
|
|
5
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
1
|
+
import { browser } from '@wdio/globals';
|
|
2
|
+
import { waitUntil, enhanceError, compareText, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils';
|
|
6
3
|
async function conditionAttr(el, attribute) {
|
|
7
4
|
const attr = await el.getAttribute(attribute);
|
|
8
5
|
if (typeof attr !== 'string') {
|
|
@@ -17,56 +14,53 @@ async function conditionAttrAndValue(el, attribute, value, options) {
|
|
|
17
14
|
if (typeof attr !== 'string') {
|
|
18
15
|
return { result: false, value: attr };
|
|
19
16
|
}
|
|
20
|
-
return
|
|
17
|
+
return compareText(attr, value, options);
|
|
21
18
|
}
|
|
22
|
-
function toHaveAttributeAndValueFn(received, attribute, value, options = {}) {
|
|
19
|
+
export function toHaveAttributeAndValueFn(received, attribute, value, options = {}) {
|
|
23
20
|
const isNot = this.isNot;
|
|
24
21
|
const { expectation = 'attribute', verb = 'have' } = this;
|
|
25
22
|
return browser.call(async () => {
|
|
26
23
|
let el = await received;
|
|
27
24
|
let attr;
|
|
28
|
-
const pass = await
|
|
29
|
-
const result = await
|
|
25
|
+
const pass = await waitUntil(async () => {
|
|
26
|
+
const result = await executeCommand.call(this, el, conditionAttrAndValue, options, [attribute, value, options]);
|
|
30
27
|
el = result.el;
|
|
31
28
|
attr = result.values;
|
|
32
29
|
return result.success;
|
|
33
30
|
}, isNot, options);
|
|
34
|
-
|
|
35
|
-
const expected =
|
|
36
|
-
const message =
|
|
31
|
+
updateElementsArray(pass, received, el);
|
|
32
|
+
const expected = wrapExpectedWithArray(el, attr, value);
|
|
33
|
+
const message = enhanceError(el, expected, attr, this, verb, expectation, attribute, options);
|
|
37
34
|
return {
|
|
38
35
|
pass,
|
|
39
36
|
message: () => message
|
|
40
37
|
};
|
|
41
38
|
});
|
|
42
39
|
}
|
|
43
|
-
|
|
44
|
-
function toHaveAttributeFn(received, attribute) {
|
|
40
|
+
export function toHaveAttributeFn(received, attribute) {
|
|
45
41
|
const isNot = this.isNot;
|
|
46
42
|
const { expectation = 'attribute', verb = 'have' } = this;
|
|
47
43
|
return browser.call(async () => {
|
|
48
44
|
let el = await received;
|
|
49
|
-
const pass = await
|
|
50
|
-
const result = await
|
|
45
|
+
const pass = await waitUntil(async () => {
|
|
46
|
+
const result = await executeCommand.call(this, el, conditionAttr, {}, [attribute]);
|
|
51
47
|
el = result.el;
|
|
52
48
|
return result.success;
|
|
53
49
|
}, isNot, {});
|
|
54
|
-
|
|
55
|
-
const message =
|
|
50
|
+
updateElementsArray(pass, received, el);
|
|
51
|
+
const message = enhanceError(el, !isNot, pass, this, verb, expectation, attribute, {});
|
|
56
52
|
return {
|
|
57
53
|
pass,
|
|
58
54
|
message: () => message
|
|
59
55
|
};
|
|
60
56
|
});
|
|
61
57
|
}
|
|
62
|
-
|
|
63
|
-
function toHaveAttribute(...args) {
|
|
58
|
+
export function toHaveAttribute(...args) {
|
|
64
59
|
if (args.length === 3 || args.length === 4) {
|
|
65
|
-
return
|
|
60
|
+
return toHaveAttributeAndValueFn.call(this, ...args);
|
|
66
61
|
}
|
|
67
62
|
else {
|
|
68
|
-
return
|
|
63
|
+
return toHaveAttributeFn.call(this, ...args);
|
|
69
64
|
}
|
|
70
65
|
}
|
|
71
|
-
|
|
72
|
-
exports.toHaveAttr = toHaveAttribute;
|
|
66
|
+
export const toHaveAttr = toHaveAttribute;
|
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
5
|
-
const toHaveAttribute_1 = require("./toHaveAttribute");
|
|
6
|
-
function toHaveAttributeContainingFn(el, attribute, value, options = {}) {
|
|
7
|
-
return toHaveAttribute_1.toHaveAttributeAndValueFn.call(this, el, attribute, value, {
|
|
1
|
+
import { toHaveAttributeAndValueFn } from './toHaveAttribute';
|
|
2
|
+
export function toHaveAttributeContaining(el, attribute, value, options = {}) {
|
|
3
|
+
return toHaveAttributeAndValueFn.call(this, el, attribute, value, {
|
|
8
4
|
...options,
|
|
9
5
|
containing: true
|
|
10
6
|
});
|
|
11
7
|
}
|
|
12
|
-
|
|
13
|
-
return expectAdapter_1.runExpect.call(this || {}, toHaveAttributeContainingFn, args);
|
|
14
|
-
}
|
|
15
|
-
exports.toHaveAttributeContaining = toHaveAttributeContaining;
|
|
16
|
-
exports.toHaveAttrContaining = toHaveAttributeContaining;
|
|
8
|
+
export const toHaveAttrContaining = toHaveAttributeContaining;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.toHaveChildren = void 0;
|
|
4
|
-
const utils_1 = require("../../utils");
|
|
5
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
1
|
+
import { browser } from '@wdio/globals';
|
|
2
|
+
import { waitUntil, enhanceError, compareNumbers, numberError, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils';
|
|
6
3
|
async function condition(el, options) {
|
|
7
4
|
const children = await el.$$('./*');
|
|
8
5
|
if (typeof options.lte !== 'number' &&
|
|
@@ -10,15 +7,15 @@ async function condition(el, options) {
|
|
|
10
7
|
typeof options.eq !== 'number') {
|
|
11
8
|
return {
|
|
12
9
|
result: children.length > 0,
|
|
13
|
-
value: children
|
|
10
|
+
value: children?.length
|
|
14
11
|
};
|
|
15
12
|
}
|
|
16
13
|
return {
|
|
17
|
-
result:
|
|
18
|
-
value: children
|
|
14
|
+
result: compareNumbers(children?.length, options),
|
|
15
|
+
value: children?.length
|
|
19
16
|
};
|
|
20
17
|
}
|
|
21
|
-
function
|
|
18
|
+
export function toHaveChildren(received, expected, options = {}) {
|
|
22
19
|
const isNot = this.isNot;
|
|
23
20
|
const { expectation = 'children', verb = 'have' } = this;
|
|
24
21
|
let numberOptions;
|
|
@@ -31,23 +28,19 @@ function toHaveChildrenFn(received, expected, options = {}) {
|
|
|
31
28
|
return browser.call(async () => {
|
|
32
29
|
let el = await received;
|
|
33
30
|
let children;
|
|
34
|
-
const pass = await
|
|
35
|
-
const result = await
|
|
31
|
+
const pass = await waitUntil(async () => {
|
|
32
|
+
const result = await executeCommand.call(this, el, condition, numberOptions, [numberOptions]);
|
|
36
33
|
el = result.el;
|
|
37
34
|
children = result.values;
|
|
38
35
|
return result.success;
|
|
39
36
|
}, isNot, { ...numberOptions, ...options });
|
|
40
|
-
|
|
41
|
-
const error =
|
|
42
|
-
const expected =
|
|
43
|
-
const message =
|
|
37
|
+
updateElementsArray(pass, received, el);
|
|
38
|
+
const error = numberError(numberOptions);
|
|
39
|
+
const expected = wrapExpectedWithArray(el, children, error);
|
|
40
|
+
const message = enhanceError(el, expected, children, this, verb, expectation, '', numberOptions);
|
|
44
41
|
return {
|
|
45
42
|
pass,
|
|
46
43
|
message: () => message
|
|
47
44
|
};
|
|
48
45
|
});
|
|
49
46
|
}
|
|
50
|
-
function toHaveChildren(...args) {
|
|
51
|
-
return expectAdapter_1.runExpect.call(this || {}, toHaveChildrenFn, args);
|
|
52
|
-
}
|
|
53
|
-
exports.toHaveChildren = toHaveChildren;
|