expect-webdriverio 3.3.1 → 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 +51 -44
- package/types/jest-global.d.ts +1 -1
- package/types/standalone.d.ts +2 -2
- 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
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.toHaveClass = exports.toHaveElementClass = 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, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils';
|
|
6
3
|
async function condition(el, attribute, value, options) {
|
|
7
4
|
const { ignoreCase = false, trim = false, containing = false } = options;
|
|
8
5
|
let attr = await el.getAttribute(attribute);
|
|
@@ -27,33 +24,27 @@ async function condition(el, attribute, value, options) {
|
|
|
27
24
|
result: valueInClasses
|
|
28
25
|
};
|
|
29
26
|
}
|
|
30
|
-
function
|
|
27
|
+
export function toHaveElementClass(...args) {
|
|
28
|
+
return toHaveClass.call(this || {}, ...args);
|
|
29
|
+
}
|
|
30
|
+
export function toHaveClass(received, className, options = {}) {
|
|
31
31
|
const isNot = this.isNot;
|
|
32
32
|
const { expectation = 'class', verb = 'have' } = this;
|
|
33
33
|
const attribute = 'class';
|
|
34
34
|
return browser.call(async () => {
|
|
35
35
|
let el = await received;
|
|
36
36
|
let attr;
|
|
37
|
-
const pass = await
|
|
38
|
-
const result = await
|
|
37
|
+
const pass = await waitUntil(async () => {
|
|
38
|
+
const result = await executeCommand.call(this, el, condition, options, [attribute, className, options]);
|
|
39
39
|
el = result.el;
|
|
40
40
|
attr = result.values;
|
|
41
41
|
return result.success;
|
|
42
42
|
}, isNot, options);
|
|
43
|
-
|
|
44
|
-
const message =
|
|
43
|
+
updateElementsArray(pass, received, el);
|
|
44
|
+
const message = enhanceError(el, wrapExpectedWithArray(el, attr, className), attr, this, verb, expectation, '', options);
|
|
45
45
|
return {
|
|
46
46
|
pass,
|
|
47
47
|
message: () => message
|
|
48
48
|
};
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
|
-
function toHaveElementClass(...args) {
|
|
52
|
-
return expectAdapter_1.runExpect.call(this || {}, toHaveElementClassFn, args);
|
|
53
|
-
}
|
|
54
|
-
exports.toHaveElementClass = toHaveElementClass;
|
|
55
|
-
function toHaveClass(...args) {
|
|
56
|
-
console.warn('expect(...).toHaveClass is deprecated and will be removed in next release. Use toHaveElementClass instead.');
|
|
57
|
-
return expectAdapter_1.runExpect.call(this || {}, toHaveElementClassFn, args);
|
|
58
|
-
}
|
|
59
|
-
exports.toHaveClass = toHaveClass;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { toHaveAttributeAndValueFn } from './toHaveAttribute';
|
|
2
|
+
export function toHaveElementClassContaining(...args) {
|
|
3
|
+
return toHaveClassContaining.call(this, ...args);
|
|
4
|
+
}
|
|
5
|
+
export function toHaveClassContaining(el, className, options = {}) {
|
|
6
|
+
return toHaveAttributeAndValueFn.call(this, el, 'class', className, {
|
|
7
|
+
...options,
|
|
8
|
+
containing: true
|
|
9
|
+
});
|
|
10
|
+
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.toHaveElementProperty = exports.toHaveElementPropertyFn = 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 condition(el, property, value, options = {}) {
|
|
7
4
|
const { asString = false } = options;
|
|
8
5
|
let prop = await el.getProperty(property);
|
|
@@ -16,28 +13,28 @@ async function condition(el, property, value, options = {}) {
|
|
|
16
13
|
return { result: prop === value, value: prop };
|
|
17
14
|
}
|
|
18
15
|
prop = prop.toString();
|
|
19
|
-
return
|
|
16
|
+
return compareText(prop, value, options);
|
|
20
17
|
}
|
|
21
|
-
function
|
|
18
|
+
export function toHaveElementProperty(received, property, value, options = {}) {
|
|
22
19
|
const isNot = this.isNot;
|
|
23
20
|
const { expectation = 'property', verb = 'have' } = this;
|
|
24
21
|
return browser.call(async () => {
|
|
25
22
|
let el = await received;
|
|
26
23
|
let prop;
|
|
27
|
-
const pass = await
|
|
28
|
-
const result = await
|
|
24
|
+
const pass = await waitUntil(async () => {
|
|
25
|
+
const result = await executeCommand.call(this, el, condition, options, [property, value]);
|
|
29
26
|
el = result.el;
|
|
30
27
|
prop = result.values;
|
|
31
28
|
return result.success;
|
|
32
29
|
}, isNot, options);
|
|
33
|
-
|
|
30
|
+
updateElementsArray(pass, received, el);
|
|
34
31
|
let message;
|
|
35
32
|
if (value === undefined) {
|
|
36
|
-
message =
|
|
33
|
+
message = enhanceError(el, !isNot, pass, this, verb, expectation, property, options);
|
|
37
34
|
}
|
|
38
35
|
else {
|
|
39
|
-
const expected =
|
|
40
|
-
message =
|
|
36
|
+
const expected = wrapExpectedWithArray(el, prop, value);
|
|
37
|
+
message = enhanceError(el, expected, prop, this, verb, expectation, property, options);
|
|
41
38
|
}
|
|
42
39
|
return {
|
|
43
40
|
pass,
|
|
@@ -45,8 +42,3 @@ function toHaveElementPropertyFn(received, property, value, options = {}) {
|
|
|
45
42
|
};
|
|
46
43
|
});
|
|
47
44
|
}
|
|
48
|
-
exports.toHaveElementPropertyFn = toHaveElementPropertyFn;
|
|
49
|
-
function toHaveElementProperty(...args) {
|
|
50
|
-
return expectAdapter_1.runExpect.call(this || {}, toHaveElementPropertyFn, args);
|
|
51
|
-
}
|
|
52
|
-
exports.toHaveElementProperty = toHaveElementProperty;
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
5
|
-
const toHaveAttribute_1 = require("./toHaveAttribute");
|
|
6
|
-
function toHaveHrefFn(el, href, options = {}) {
|
|
7
|
-
return toHaveAttribute_1.toHaveAttributeAndValueFn.call(this, el, 'href', href, options);
|
|
1
|
+
import { toHaveAttributeAndValueFn } from './toHaveAttribute';
|
|
2
|
+
export function toHaveHref(el, href, options = {}) {
|
|
3
|
+
return toHaveAttributeAndValueFn.call(this, el, 'href', href, options);
|
|
8
4
|
}
|
|
9
|
-
|
|
10
|
-
function toHaveHref(...args) {
|
|
11
|
-
return expectAdapter_1.runExpect.call(this || {}, toHaveHrefFn, args);
|
|
12
|
-
}
|
|
13
|
-
exports.toHaveHref = toHaveHref;
|
|
14
|
-
exports.toHaveLink = toHaveHref;
|
|
5
|
+
export const toHaveLink = toHaveHref;
|
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
5
|
-
const toHaveHref_1 = require("./toHaveHref");
|
|
6
|
-
function toHaveHrefContainingFn(el, href, options = {}) {
|
|
7
|
-
return toHaveHref_1.toHaveHrefFn.call(this, el, href, {
|
|
1
|
+
import { toHaveHref } from './toHaveHref';
|
|
2
|
+
export function toHaveHrefContaining(el, href, options = {}) {
|
|
3
|
+
return toHaveHref.call(this, el, href, {
|
|
8
4
|
...options,
|
|
9
5
|
containing: true
|
|
10
6
|
});
|
|
11
7
|
}
|
|
12
|
-
|
|
13
|
-
return expectAdapter_1.runExpect.call(this || {}, toHaveHrefContainingFn, args);
|
|
14
|
-
}
|
|
15
|
-
exports.toHaveHrefContaining = toHaveHrefContaining;
|
|
16
|
-
exports.toHaveLinkContaining = toHaveHrefContaining;
|
|
8
|
+
export const toHaveLinkContaining = toHaveHrefContaining;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
5
|
-
const toHaveAttribute_1 = require("./toHaveAttribute");
|
|
6
|
-
function toHaveIdFn(el, id, options = {}) {
|
|
7
|
-
return toHaveAttribute_1.toHaveAttributeAndValueFn.call(this, el, 'id', id, options);
|
|
1
|
+
import { toHaveAttributeAndValueFn } from './toHaveAttribute';
|
|
2
|
+
export function toHaveId(el, id, options = {}) {
|
|
3
|
+
return toHaveAttributeAndValueFn.call(this, el, 'id', id, options);
|
|
8
4
|
}
|
|
9
|
-
exports.toHaveIdFn = toHaveIdFn;
|
|
10
|
-
function toHaveId(...args) {
|
|
11
|
-
return expectAdapter_1.runExpect.call(this || {}, toHaveIdFn, args);
|
|
12
|
-
}
|
|
13
|
-
exports.toHaveId = toHaveId;
|
|
@@ -1,33 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.toHaveStyle = exports.toHaveStyleFn = 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, compareStyle, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils';
|
|
6
3
|
async function condition(el, style, options) {
|
|
7
|
-
return
|
|
4
|
+
return compareStyle(el, style, options);
|
|
8
5
|
}
|
|
9
|
-
function
|
|
6
|
+
export function toHaveStyle(received, style, options = {}) {
|
|
10
7
|
const isNot = this.isNot;
|
|
11
8
|
const { expectation = 'style', verb = 'have' } = this;
|
|
12
9
|
return browser.call(async () => {
|
|
13
10
|
let el = await received;
|
|
14
11
|
let actualStyle;
|
|
15
|
-
const pass = await
|
|
16
|
-
const result = await
|
|
12
|
+
const pass = await waitUntil(async () => {
|
|
13
|
+
const result = await executeCommand.call(this, el, condition, options, [style, options]);
|
|
17
14
|
el = result.el;
|
|
18
15
|
actualStyle = result.values;
|
|
19
16
|
return result.success;
|
|
20
17
|
}, isNot, options);
|
|
21
|
-
|
|
22
|
-
const message =
|
|
18
|
+
updateElementsArray(pass, received, el);
|
|
19
|
+
const message = enhanceError(el, wrapExpectedWithArray(el, actualStyle, style), actualStyle, this, verb, expectation, '', options);
|
|
23
20
|
return {
|
|
24
21
|
pass,
|
|
25
22
|
message: () => message
|
|
26
23
|
};
|
|
27
24
|
});
|
|
28
25
|
}
|
|
29
|
-
exports.toHaveStyleFn = toHaveStyleFn;
|
|
30
|
-
function toHaveStyle(...args) {
|
|
31
|
-
return expectAdapter_1.runExpect.call(this || {}, toHaveStyleFn, args);
|
|
32
|
-
}
|
|
33
|
-
exports.toHaveStyle = toHaveStyle;
|
|
@@ -1,37 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.toHaveText = exports.toHaveTextFn = 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, compareTextWithArray, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils';
|
|
6
3
|
async function condition(el, text, options) {
|
|
7
4
|
const actualText = await el.getText();
|
|
8
5
|
if (Array.isArray(text)) {
|
|
9
|
-
return
|
|
6
|
+
return compareTextWithArray(actualText, text, options);
|
|
10
7
|
}
|
|
11
|
-
return
|
|
8
|
+
return compareText(actualText, text, options);
|
|
12
9
|
}
|
|
13
|
-
function
|
|
10
|
+
export function toHaveText(received, text, options = {}) {
|
|
14
11
|
const isNot = this.isNot;
|
|
15
12
|
const { expectation = 'text', verb = 'have' } = this;
|
|
16
13
|
return browser.call(async () => {
|
|
17
14
|
let el = await received;
|
|
18
15
|
let actualText;
|
|
19
|
-
const pass = await
|
|
20
|
-
const result = await
|
|
16
|
+
const pass = await waitUntil(async () => {
|
|
17
|
+
const result = await executeCommand.call(this, el, condition, options, [text, options]);
|
|
21
18
|
el = result.el;
|
|
22
19
|
actualText = result.values;
|
|
23
20
|
return result.success;
|
|
24
21
|
}, isNot, options);
|
|
25
|
-
|
|
26
|
-
const message =
|
|
22
|
+
updateElementsArray(pass, received, el);
|
|
23
|
+
const message = enhanceError(el, wrapExpectedWithArray(el, actualText, text), actualText, this, verb, expectation, '', options);
|
|
27
24
|
return {
|
|
28
25
|
pass,
|
|
29
26
|
message: () => message
|
|
30
27
|
};
|
|
31
28
|
});
|
|
32
29
|
}
|
|
33
|
-
exports.toHaveTextFn = toHaveTextFn;
|
|
34
|
-
function toHaveText(...args) {
|
|
35
|
-
return expectAdapter_1.runExpect.call(this || {}, toHaveTextFn, args);
|
|
36
|
-
}
|
|
37
|
-
exports.toHaveText = toHaveText;
|
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
5
|
-
const toHaveText_1 = require("./toHaveText");
|
|
6
|
-
function toHaveTextContainingFn(el, text, options = {}) {
|
|
7
|
-
return toHaveText_1.toHaveTextFn.call(this, el, text, {
|
|
1
|
+
import { toHaveText } from './toHaveText';
|
|
2
|
+
export function toHaveTextContaining(el, text, options = {}) {
|
|
3
|
+
return toHaveText.call(this, el, text, {
|
|
8
4
|
...options,
|
|
9
5
|
containing: true
|
|
10
6
|
});
|
|
11
7
|
}
|
|
12
|
-
function toHaveTextContaining(...args) {
|
|
13
|
-
return expectAdapter_1.runExpect.call(this || {}, toHaveTextContainingFn, args);
|
|
14
|
-
}
|
|
15
|
-
exports.toHaveTextContaining = toHaveTextContaining;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
5
|
-
const toHaveElementProperty_1 = require("./toHaveElementProperty");
|
|
6
|
-
function toHaveValueFn(el, value, options = {}) {
|
|
7
|
-
return toHaveElementProperty_1.toHaveElementPropertyFn.call(this, el, 'value', value, options);
|
|
1
|
+
import { toHaveElementProperty } from './toHaveElementProperty';
|
|
2
|
+
export function toHaveValue(el, value, options = {}) {
|
|
3
|
+
return toHaveElementProperty.call(this, el, 'value', value, options);
|
|
8
4
|
}
|
|
9
|
-
exports.toHaveValueFn = toHaveValueFn;
|
|
10
|
-
function toHaveValue(...args) {
|
|
11
|
-
return expectAdapter_1.runExpect.call(this || {}, toHaveValueFn, args);
|
|
12
|
-
}
|
|
13
|
-
exports.toHaveValue = toHaveValue;
|
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
5
|
-
const toHaveValue_1 = require("./toHaveValue");
|
|
6
|
-
function toHaveValueContainingFn(el, value, options = {}) {
|
|
7
|
-
return toHaveValue_1.toHaveValueFn.call(this, el, value, {
|
|
1
|
+
import { toHaveValue } from './toHaveValue';
|
|
2
|
+
export function toHaveValueContaining(el, value, options = {}) {
|
|
3
|
+
return toHaveValue.call(this, el, value, {
|
|
8
4
|
...options,
|
|
9
5
|
containing: true
|
|
10
6
|
});
|
|
11
7
|
}
|
|
12
|
-
function toHaveValueContaining(...args) {
|
|
13
|
-
return expectAdapter_1.runExpect.call(this || {}, toHaveValueContainingFn, args);
|
|
14
|
-
}
|
|
15
|
-
exports.toHaveValueContaining = toHaveValueContaining;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const refetchElements_1 = require("../../util/refetchElements");
|
|
6
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
7
|
-
function toBeElementsArrayOfSizeFn(received, expected, options = {}) {
|
|
1
|
+
import { browser } from '@wdio/globals';
|
|
2
|
+
import { waitUntil, enhanceError, compareNumbers, numberError, updateElementsArray } from '../../utils';
|
|
3
|
+
import { refetchElements } from '../../util/refetchElements';
|
|
4
|
+
export function toBeElementsArrayOfSize(received, expected, options = {}) {
|
|
8
5
|
const isNot = this.isNot;
|
|
9
6
|
const { expectation = 'elements array of size', verb = 'be' } = this;
|
|
10
7
|
let numberOptions;
|
|
@@ -20,20 +17,16 @@ function toBeElementsArrayOfSizeFn(received, expected, options = {}) {
|
|
|
20
17
|
return browser.call(async () => {
|
|
21
18
|
let elements = await received;
|
|
22
19
|
const arrLength = elements.length;
|
|
23
|
-
const pass = await
|
|
24
|
-
elements = await
|
|
25
|
-
return
|
|
20
|
+
const pass = await waitUntil(async () => {
|
|
21
|
+
elements = await refetchElements(elements, numberOptions.wait, true);
|
|
22
|
+
return compareNumbers(elements.length, numberOptions);
|
|
26
23
|
}, isNot, { ...numberOptions, ...options });
|
|
27
|
-
|
|
28
|
-
const error =
|
|
29
|
-
const message =
|
|
24
|
+
updateElementsArray(pass, received, elements, true);
|
|
25
|
+
const error = numberError(numberOptions);
|
|
26
|
+
const message = enhanceError(elements, error, arrLength, this, verb, expectation, '', numberOptions);
|
|
30
27
|
return {
|
|
31
28
|
pass,
|
|
32
29
|
message: () => message
|
|
33
30
|
};
|
|
34
31
|
});
|
|
35
32
|
}
|
|
36
|
-
function toBeElementsArrayOfSize(...args) {
|
|
37
|
-
return expectAdapter_1.runExpect.call(this || {}, toBeElementsArrayOfSizeFn, args);
|
|
38
|
-
}
|
|
39
|
-
exports.toBeElementsArrayOfSize = toBeElementsArrayOfSize;
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const toBeRequestedTimes_1 = require("./toBeRequestedTimes");
|
|
5
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
function toBeRequestedFn(received, options = {}) {
|
|
7
|
-
return toBeRequestedTimes_1.toBeRequestedTimes.call({ ...(this || {}), expectation: 'called' }, received, { ...options, gte: 1 });
|
|
1
|
+
import { toBeRequestedTimes } from './toBeRequestedTimes';
|
|
2
|
+
export function toBeRequested(received, options = {}) {
|
|
3
|
+
return toBeRequestedTimes.call({ ...(this || {}), expectation: 'called' }, received, { ...options, gte: 1 });
|
|
8
4
|
}
|
|
9
|
-
function toBeRequested(...args) {
|
|
10
|
-
return expectAdapter_1.runExpect.call(this || {}, toBeRequestedFn, args);
|
|
11
|
-
}
|
|
12
|
-
exports.toBeRequested = toBeRequested;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
const formatMessage_1 = require("../../util/formatMessage");
|
|
7
|
-
function toBeRequestedTimesFn(received, expected = {}, options = {}) {
|
|
1
|
+
import { browser } from '@wdio/globals';
|
|
2
|
+
import { waitUntil, enhanceError, compareNumbers } from '../../utils';
|
|
3
|
+
import { numberError } from '../../util/formatMessage';
|
|
4
|
+
export function toBeRequestedTimes(received, expected = {}, options = {}) {
|
|
8
5
|
const isNot = this.isNot || false;
|
|
9
6
|
const { expectation = `called${typeof expected === 'number' ? ' ' + expected : ''} time${expected !== 1 ? 's' : ''}`, verb = 'be' } = this;
|
|
10
7
|
let numberOptions;
|
|
@@ -16,20 +13,15 @@ function toBeRequestedTimesFn(received, expected = {}, options = {}) {
|
|
|
16
13
|
}
|
|
17
14
|
return browser.call(async () => {
|
|
18
15
|
let actual;
|
|
19
|
-
const pass = await
|
|
16
|
+
const pass = await waitUntil(async () => {
|
|
20
17
|
actual = received.calls.length;
|
|
21
|
-
return
|
|
18
|
+
return compareNumbers(actual, numberOptions);
|
|
22
19
|
}, isNot, { ...numberOptions, ...options });
|
|
23
|
-
const error =
|
|
24
|
-
const message =
|
|
20
|
+
const error = numberError(numberOptions);
|
|
21
|
+
const message = enhanceError('mock', error, actual, this, verb, expectation, '', numberOptions);
|
|
25
22
|
return {
|
|
26
23
|
pass,
|
|
27
24
|
message: () => message
|
|
28
25
|
};
|
|
29
26
|
});
|
|
30
27
|
}
|
|
31
|
-
exports.toBeRequestedTimesFn = toBeRequestedTimesFn;
|
|
32
|
-
function toBeRequestedTimes(...args) {
|
|
33
|
-
return expectAdapter_1.runExpect.call(this || {}, toBeRequestedTimesFn, args);
|
|
34
|
-
}
|
|
35
|
-
exports.toBeRequestedTimes = toBeRequestedTimes;
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const utils_1 = require("../../utils");
|
|
5
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
const jasmineUtils_1 = require("../../jasmineUtils");
|
|
1
|
+
import { browser } from '@wdio/globals';
|
|
2
|
+
import { waitUntil, enhanceError } from '../../utils';
|
|
3
|
+
import { equals } from '../../jasmineUtils';
|
|
7
4
|
const STR_LIMIT = 80;
|
|
8
5
|
const KEY_LIMIT = 12;
|
|
9
|
-
function
|
|
6
|
+
export function toBeRequestedWith(received, requestedWith = {}, options = {}) {
|
|
10
7
|
const isNot = this.isNot || false;
|
|
11
8
|
const { expectation = 'called with', verb = 'be' } = this;
|
|
12
9
|
return browser.call(async () => {
|
|
13
10
|
let actual;
|
|
14
|
-
const pass = await
|
|
11
|
+
const pass = await waitUntil(async () => {
|
|
15
12
|
for (const call of received.calls) {
|
|
16
13
|
actual = call;
|
|
17
14
|
if (methodMatcher(call.method, requestedWith.method) &&
|
|
@@ -26,14 +23,13 @@ function toBeRequestedWithFn(received, requestedWith = {}, options = {}) {
|
|
|
26
23
|
}
|
|
27
24
|
return false;
|
|
28
25
|
}, isNot, { ...options, wait: isNot ? 0 : options.wait });
|
|
29
|
-
const message =
|
|
26
|
+
const message = enhanceError('mock', minifyRequestedWith(requestedWith), minifyRequestMock(actual, requestedWith) || 'was not called', this, verb, expectation, '', options);
|
|
30
27
|
return {
|
|
31
28
|
pass,
|
|
32
29
|
message: () => message,
|
|
33
30
|
};
|
|
34
31
|
});
|
|
35
32
|
}
|
|
36
|
-
exports.toBeRequestedWithFn = toBeRequestedWithFn;
|
|
37
33
|
const methodMatcher = (method, expected) => {
|
|
38
34
|
if (typeof expected === 'undefined') {
|
|
39
35
|
return true;
|
|
@@ -66,7 +62,7 @@ const urlMatcher = (url, expected) => {
|
|
|
66
62
|
if (typeof expected === 'function') {
|
|
67
63
|
return expected(url);
|
|
68
64
|
}
|
|
69
|
-
return
|
|
65
|
+
return equals(url, expected);
|
|
70
66
|
};
|
|
71
67
|
const headersMatcher = (headers, expected) => {
|
|
72
68
|
if (typeof expected === 'undefined') {
|
|
@@ -75,7 +71,7 @@ const headersMatcher = (headers, expected) => {
|
|
|
75
71
|
if (typeof expected === 'function') {
|
|
76
72
|
return expected(headers);
|
|
77
73
|
}
|
|
78
|
-
return
|
|
74
|
+
return equals(headers, expected);
|
|
79
75
|
};
|
|
80
76
|
const bodyMatcher = (body, expected) => {
|
|
81
77
|
if (typeof expected === 'undefined') {
|
|
@@ -97,7 +93,7 @@ const bodyMatcher = (body, expected) => {
|
|
|
97
93
|
return false;
|
|
98
94
|
}
|
|
99
95
|
}
|
|
100
|
-
return
|
|
96
|
+
return equals(parsedBody, expected);
|
|
101
97
|
};
|
|
102
98
|
const isExpectedJsonLike = (expected) => {
|
|
103
99
|
if (typeof expected === 'undefined') {
|
|
@@ -112,14 +108,13 @@ const isExpectedJsonLike = (expected) => {
|
|
|
112
108
|
actualSample instanceof RegExp === false));
|
|
113
109
|
};
|
|
114
110
|
const isMatcher = (filter) => {
|
|
115
|
-
|
|
116
|
-
return typeof ((_a = filter.__proto__) === null || _a === void 0 ? void 0 : _a.asymmetricMatch) === 'function';
|
|
111
|
+
return typeof filter.__proto__?.asymmetricMatch === 'function';
|
|
117
112
|
};
|
|
118
113
|
const tryParseBody = (jsonString, fallback = null) => {
|
|
119
114
|
try {
|
|
120
115
|
return typeof jsonString === 'undefined' ? fallback : JSON.parse(jsonString);
|
|
121
116
|
}
|
|
122
|
-
catch
|
|
117
|
+
catch {
|
|
123
118
|
return fallback;
|
|
124
119
|
}
|
|
125
120
|
};
|
|
@@ -212,7 +207,6 @@ const deleteUndefinedValues = (obj, baseline = obj) => {
|
|
|
212
207
|
}
|
|
213
208
|
});
|
|
214
209
|
};
|
|
215
|
-
function
|
|
216
|
-
return
|
|
210
|
+
export function toBeRequestedWithResponse(...args) {
|
|
211
|
+
return toBeRequestedWith.call(this, ...args);
|
|
217
212
|
}
|
|
218
|
-
exports.toBeRequestedWith = toBeRequestedWith;
|
package/lib/matchers.js
CHANGED
|
@@ -1,41 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as toHaveTitle from './matchers/browser/toHaveTitle.js';
|
|
2
|
+
import * as toHaveTitleContaining from './matchers/browser/toHaveTitleContaining.js';
|
|
3
|
+
import * as toHaveUrl from './matchers/browser/toHaveUrl.js';
|
|
4
|
+
import * as toHaveUrlContaining from './matchers/browser/toHaveUrlContaining.js';
|
|
5
|
+
import * as toBeElementsArrayOfSize from './matchers/elements/toBeElementsArrayOfSize.js';
|
|
6
|
+
import * as toBeClickable from './matchers/element/toBeClickable.js';
|
|
7
|
+
import * as toBeDisabled from './matchers/element/toBeDisabled.js';
|
|
8
|
+
import * as toBeDisplayed from './matchers/element/toBeDisplayed.js';
|
|
9
|
+
import * as toBeDisplayedInViewport from './matchers/element/toBeDisplayedInViewport.js';
|
|
10
|
+
import * as toBeEnabled from './matchers/element/toBeEnabled.js';
|
|
11
|
+
import * as toBeExisting from './matchers/element/toBeExisting.js';
|
|
12
|
+
import * as toBeFocused from './matchers/element/toBeFocused.js';
|
|
13
|
+
import * as toBeSelected from './matchers/element/toBeSelected.js';
|
|
14
|
+
import * as toHaveAttribute from './matchers/element/toHaveAttribute.js';
|
|
15
|
+
import * as toHaveAttributeContaining from './matchers/element/toHaveAttributeContaining.js';
|
|
16
|
+
import * as toHaveChildren from './matchers/element/toHaveChildren.js';
|
|
17
|
+
import * as toHaveClass from './matchers/element/toHaveClass.js';
|
|
18
|
+
import * as toHaveClassContaining from './matchers/element/toHaveClassContaining.js';
|
|
19
|
+
import * as toHaveHref from './matchers/element/toHaveHref.js';
|
|
20
|
+
import * as toHaveHrefContaining from './matchers/element/toHaveHrefContaining.js';
|
|
21
|
+
import * as toHaveId from './matchers/element/toHaveId.js';
|
|
22
|
+
import * as toHaveElementProperty from './matchers/element/toHaveElementProperty.js';
|
|
23
|
+
import * as toHaveText from './matchers/element/toHaveText.js';
|
|
24
|
+
import * as toHaveTextContaining from './matchers/element/toHaveTextContaining.js';
|
|
25
|
+
import * as toHaveValue from './matchers/element/toHaveValue.js';
|
|
26
|
+
import * as toHaveValueContaining from './matchers/element/toHaveValueContaining.js';
|
|
27
|
+
import * as toHaveStyle from './matchers/element/toHaveStyle.js';
|
|
28
|
+
import * as toBeRequested from './matchers/mock/toBeRequested.js';
|
|
29
|
+
import * as toBeRequestedTimes from './matchers/mock/toBeRequestedTimes.js';
|
|
30
|
+
import * as toBeRequestedWith from './matchers/mock/toBeRequestedWith.js';
|
|
3
31
|
const matchers = {
|
|
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
|
-
...require('./matchers/mock/toBeRequestedWithResponse'),
|
|
32
|
+
...toHaveTitle,
|
|
33
|
+
...toHaveTitleContaining,
|
|
34
|
+
...toHaveUrl,
|
|
35
|
+
...toHaveUrlContaining,
|
|
36
|
+
...toBeElementsArrayOfSize,
|
|
37
|
+
...toBeClickable,
|
|
38
|
+
...toBeDisabled,
|
|
39
|
+
...toBeDisplayed,
|
|
40
|
+
...toBeDisplayedInViewport,
|
|
41
|
+
...toBeEnabled,
|
|
42
|
+
...toBeExisting,
|
|
43
|
+
...toBeFocused,
|
|
44
|
+
...toBeSelected,
|
|
45
|
+
...toHaveAttribute,
|
|
46
|
+
...toHaveAttributeContaining,
|
|
47
|
+
...toHaveChildren,
|
|
48
|
+
...toHaveClass,
|
|
49
|
+
...toHaveClassContaining,
|
|
50
|
+
...toHaveHref,
|
|
51
|
+
...toHaveHrefContaining,
|
|
52
|
+
...toHaveId,
|
|
53
|
+
...toHaveElementProperty,
|
|
54
|
+
...toHaveText,
|
|
55
|
+
...toHaveTextContaining,
|
|
56
|
+
...toHaveValue,
|
|
57
|
+
...toHaveValueContaining,
|
|
58
|
+
...toHaveStyle,
|
|
59
|
+
...toBeRequested,
|
|
60
|
+
...toBeRequestedTimes,
|
|
61
|
+
...toBeRequestedWith,
|
|
35
62
|
};
|
|
36
|
-
Object.keys(matchers).forEach(key => {
|
|
63
|
+
Object.keys(matchers).forEach((key) => {
|
|
37
64
|
if (key.endsWith('Fn')) {
|
|
38
65
|
delete matchers[key];
|
|
39
66
|
}
|
|
40
67
|
});
|
|
41
|
-
|
|
68
|
+
export default matchers;
|
package/lib/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|