expect-webdriverio 4.5.2 → 4.6.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.
- package/lib/constants.js +2 -0
- package/lib/matchers/browser/toHaveClipboardText.js +38 -0
- package/lib/matchers/browser/toHaveTitle.js +23 -4
- package/lib/matchers/browser/toHaveUrl.js +23 -4
- package/lib/matchers/element/toBeClickable.js +13 -2
- package/lib/matchers/element/toBeDisabled.js +13 -2
- package/lib/matchers/element/toBeDisplayed.js +13 -2
- package/lib/matchers/element/toBeDisplayedInViewport.js +13 -2
- package/lib/matchers/element/toBeEnabled.js +13 -2
- package/lib/matchers/element/toBeExisting.js +13 -2
- package/lib/matchers/element/toBeFocused.js +13 -2
- package/lib/matchers/element/toBeSelected.js +25 -4
- package/lib/matchers/element/toHaveAttribute.js +26 -9
- package/lib/matchers/element/toHaveChildren.js +18 -5
- package/lib/matchers/element/toHaveClass.js +29 -6
- package/lib/matchers/element/toHaveComputedLabel.js +24 -5
- package/lib/matchers/element/toHaveComputedRole.js +24 -5
- package/lib/matchers/element/toHaveElementProperty.js +17 -4
- package/lib/matchers/element/toHaveHTML.js +23 -4
- package/lib/matchers/element/toHaveHeight.js +18 -5
- package/lib/matchers/element/toHaveHref.js +23 -3
- package/lib/matchers/element/toHaveId.js +16 -3
- package/lib/matchers/element/toHaveSize.js +18 -5
- package/lib/matchers/element/toHaveStyle.js +17 -4
- package/lib/matchers/element/toHaveText.js +23 -4
- package/lib/matchers/element/toHaveValue.js +8 -1
- package/lib/matchers/element/toHaveWidth.js +18 -5
- package/lib/matchers/elements/toBeElementsArrayOfSize.js +19 -6
- package/lib/matchers/mock/toBeRequested.js +3 -2
- package/lib/matchers/mock/toBeRequestedTimes.js +19 -6
- package/lib/matchers/mock/toBeRequestedWith.js +24 -11
- package/lib/matchers.js +4 -14
- package/package.json +2 -1
- package/types/expect-webdriverio.d.ts +74 -5
- package/lib/matchers/browser/toHaveTitleContaining.js +0 -7
- package/lib/matchers/browser/toHaveUrlContaining.js +0 -7
- package/lib/matchers/element/toHaveAttributeContaining.js +0 -8
- package/lib/matchers/element/toHaveClassContaining.js +0 -10
- package/lib/matchers/element/toHaveComputedLabelContaining.js +0 -7
- package/lib/matchers/element/toHaveComputedRoleContaining.js +0 -7
- package/lib/matchers/element/toHaveHTMLContaining.js +0 -7
- package/lib/matchers/element/toHaveHrefContaining.js +0 -8
- package/lib/matchers/element/toHaveTextContaining.js +0 -7
- package/lib/matchers/element/toHaveValueContaining.js +0 -7
package/lib/constants.js
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import logger from '@wdio/logger';
|
|
2
|
+
import { waitUntil, enhanceError, compareText } from '../../utils.js';
|
|
3
|
+
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
4
|
+
const log = logger('expect-webdriverio');
|
|
5
|
+
export async function toHaveClipboardText(browser, expectedValue, options = DEFAULT_OPTIONS) {
|
|
6
|
+
const isNot = this.isNot;
|
|
7
|
+
const { expectation = 'clipboard text', verb = 'have' } = this;
|
|
8
|
+
await options.beforeAssertion?.({
|
|
9
|
+
matcherName: 'toHaveClipboardText',
|
|
10
|
+
expectedValue,
|
|
11
|
+
options,
|
|
12
|
+
});
|
|
13
|
+
let actual;
|
|
14
|
+
const pass = await waitUntil(async () => {
|
|
15
|
+
await browser.setPermissions({ name: 'clipboard-read' }, 'granted')
|
|
16
|
+
.catch((err) => log.warn(`Couldn't set clipboard permissions: ${err}`));
|
|
17
|
+
actual = await browser.execute(() => window.navigator.clipboard.readText());
|
|
18
|
+
return compareText(actual, expectedValue, options).result;
|
|
19
|
+
}, isNot, options);
|
|
20
|
+
const message = enhanceError('browser', expectedValue, actual, this, verb, expectation, '', options);
|
|
21
|
+
const result = {
|
|
22
|
+
pass,
|
|
23
|
+
message: () => message
|
|
24
|
+
};
|
|
25
|
+
await options.afterAssertion?.({
|
|
26
|
+
matcherName: 'toHaveClipboardText',
|
|
27
|
+
expectedValue,
|
|
28
|
+
options,
|
|
29
|
+
result
|
|
30
|
+
});
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
export function toHaveClipboardTextContaining(browser, clipboardText, options = {}) {
|
|
34
|
+
return toHaveClipboardText.call(this, browser, clipboardText, {
|
|
35
|
+
...options,
|
|
36
|
+
containing: true
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -1,15 +1,34 @@
|
|
|
1
1
|
import { waitUntil, enhanceError, compareText } from '../../utils.js';
|
|
2
|
-
|
|
2
|
+
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
3
|
+
export async function toHaveTitle(browser, expectedValue, options = DEFAULT_OPTIONS) {
|
|
3
4
|
const isNot = this.isNot;
|
|
4
5
|
const { expectation = 'title', verb = 'have' } = this;
|
|
6
|
+
await options.beforeAssertion?.({
|
|
7
|
+
matcherName: 'toHaveTitle',
|
|
8
|
+
expectedValue,
|
|
9
|
+
options,
|
|
10
|
+
});
|
|
5
11
|
let actual;
|
|
6
12
|
const pass = await waitUntil(async () => {
|
|
7
13
|
actual = await browser.getTitle();
|
|
8
|
-
return compareText(actual,
|
|
14
|
+
return compareText(actual, expectedValue, options).result;
|
|
9
15
|
}, isNot, options);
|
|
10
|
-
const message = enhanceError('window',
|
|
11
|
-
|
|
16
|
+
const message = enhanceError('window', expectedValue, actual, this, verb, expectation, '', options);
|
|
17
|
+
const result = {
|
|
12
18
|
pass,
|
|
13
19
|
message: () => message
|
|
14
20
|
};
|
|
21
|
+
await options.afterAssertion?.({
|
|
22
|
+
matcherName: 'toHaveTitle',
|
|
23
|
+
expectedValue,
|
|
24
|
+
options,
|
|
25
|
+
result
|
|
26
|
+
});
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
export function toHaveTitleContaining(browser, title, options = {}) {
|
|
30
|
+
return toHaveTitle.call(this, browser, title, {
|
|
31
|
+
...options,
|
|
32
|
+
containing: true
|
|
33
|
+
});
|
|
15
34
|
}
|
|
@@ -1,15 +1,34 @@
|
|
|
1
1
|
import { waitUntil, enhanceError, compareText } from '../../utils.js';
|
|
2
|
-
|
|
2
|
+
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
3
|
+
export async function toHaveUrl(browser, expectedValue, options = DEFAULT_OPTIONS) {
|
|
3
4
|
const isNot = this.isNot;
|
|
4
5
|
const { expectation = 'url', verb = 'have' } = this;
|
|
6
|
+
await options.beforeAssertion?.({
|
|
7
|
+
matcherName: 'toHaveUrl',
|
|
8
|
+
expectedValue,
|
|
9
|
+
options,
|
|
10
|
+
});
|
|
5
11
|
let actual;
|
|
6
12
|
const pass = await waitUntil(async () => {
|
|
7
13
|
actual = await browser.getUrl();
|
|
8
|
-
return compareText(actual,
|
|
14
|
+
return compareText(actual, expectedValue, options).result;
|
|
9
15
|
}, isNot, options);
|
|
10
|
-
const message = enhanceError('window',
|
|
11
|
-
|
|
16
|
+
const message = enhanceError('window', expectedValue, actual, this, verb, expectation, '', options);
|
|
17
|
+
const result = {
|
|
12
18
|
pass,
|
|
13
19
|
message: () => message
|
|
14
20
|
};
|
|
21
|
+
await options.afterAssertion?.({
|
|
22
|
+
matcherName: 'toHaveUrl',
|
|
23
|
+
expectedValue,
|
|
24
|
+
options,
|
|
25
|
+
result
|
|
26
|
+
});
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
export function toHaveUrlContaining(browser, url, options = DEFAULT_OPTIONS) {
|
|
30
|
+
return toHaveUrl.call(this, browser, url, {
|
|
31
|
+
...options,
|
|
32
|
+
containing: true
|
|
33
|
+
});
|
|
15
34
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { executeCommandBe } from '../../utils.js';
|
|
2
|
-
|
|
2
|
+
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
3
|
+
export async function toBeClickable(received, options = DEFAULT_OPTIONS) {
|
|
3
4
|
this.expectation = this.expectation || 'clickable';
|
|
4
|
-
|
|
5
|
+
await options.beforeAssertion?.({
|
|
6
|
+
matcherName: 'toBeClickable',
|
|
7
|
+
options,
|
|
8
|
+
});
|
|
9
|
+
const result = await executeCommandBe.call(this, received, async (el) => {
|
|
5
10
|
try {
|
|
6
11
|
return el.isClickable();
|
|
7
12
|
}
|
|
@@ -9,4 +14,10 @@ export function toBeClickable(received, options = {}) {
|
|
|
9
14
|
return false;
|
|
10
15
|
}
|
|
11
16
|
}, options);
|
|
17
|
+
await options.afterAssertion?.({
|
|
18
|
+
matcherName: 'toBeClickable',
|
|
19
|
+
options,
|
|
20
|
+
result
|
|
21
|
+
});
|
|
22
|
+
return result;
|
|
12
23
|
}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { executeCommandBe } from '../../utils.js';
|
|
2
|
-
|
|
2
|
+
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
3
|
+
export async function toBeDisabled(received, options = DEFAULT_OPTIONS) {
|
|
3
4
|
this.expectation = this.expectation || 'disabled';
|
|
4
|
-
|
|
5
|
+
await options.beforeAssertion?.({
|
|
6
|
+
matcherName: 'toBeDisabled',
|
|
7
|
+
options,
|
|
8
|
+
});
|
|
9
|
+
const result = await executeCommandBe.call(this, received, async (el) => !await el.isEnabled(), options);
|
|
10
|
+
await options.afterAssertion?.({
|
|
11
|
+
matcherName: 'toBeDisabled',
|
|
12
|
+
options,
|
|
13
|
+
result
|
|
14
|
+
});
|
|
15
|
+
return result;
|
|
5
16
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { executeCommandBe } from '../../utils.js';
|
|
2
|
-
|
|
2
|
+
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
3
|
+
export async function toBeDisplayed(received, options = DEFAULT_OPTIONS) {
|
|
3
4
|
this.expectation = this.expectation || 'displayed';
|
|
4
|
-
|
|
5
|
+
await options.beforeAssertion?.({
|
|
6
|
+
matcherName: 'toBeDisplayed',
|
|
7
|
+
options,
|
|
8
|
+
});
|
|
9
|
+
const result = await executeCommandBe.call(this, received, async (el) => {
|
|
5
10
|
try {
|
|
6
11
|
return el.isDisplayed();
|
|
7
12
|
}
|
|
@@ -9,4 +14,10 @@ export async function toBeDisplayed(received, options = {}) {
|
|
|
9
14
|
return false;
|
|
10
15
|
}
|
|
11
16
|
}, options);
|
|
17
|
+
await options.afterAssertion?.({
|
|
18
|
+
matcherName: 'toBeDisplayed',
|
|
19
|
+
options,
|
|
20
|
+
result
|
|
21
|
+
});
|
|
22
|
+
return result;
|
|
12
23
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { executeCommandBe } from '../../utils.js';
|
|
2
|
-
|
|
2
|
+
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
3
|
+
export async function toBeDisplayedInViewport(received, options = DEFAULT_OPTIONS) {
|
|
3
4
|
this.expectation = this.expectation || 'displayed in viewport';
|
|
4
|
-
|
|
5
|
+
await options.beforeAssertion?.({
|
|
6
|
+
matcherName: 'toBeDisplayedInViewport',
|
|
7
|
+
options,
|
|
8
|
+
});
|
|
9
|
+
const result = await executeCommandBe.call(this, received, async (el) => {
|
|
5
10
|
try {
|
|
6
11
|
return el.isDisplayedInViewport();
|
|
7
12
|
}
|
|
@@ -9,4 +14,10 @@ export function toBeDisplayedInViewport(received, options = {}) {
|
|
|
9
14
|
return false;
|
|
10
15
|
}
|
|
11
16
|
}, options);
|
|
17
|
+
await options.afterAssertion?.({
|
|
18
|
+
matcherName: 'toBeDisplayedInViewport',
|
|
19
|
+
options,
|
|
20
|
+
result
|
|
21
|
+
});
|
|
22
|
+
return result;
|
|
12
23
|
}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { executeCommandBe } from '../../utils.js';
|
|
2
|
-
|
|
2
|
+
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
3
|
+
export async function toBeEnabled(received, options = DEFAULT_OPTIONS) {
|
|
3
4
|
this.expectation = this.expectation || 'enabled';
|
|
4
|
-
|
|
5
|
+
await options.beforeAssertion?.({
|
|
6
|
+
matcherName: 'toBeEnabled',
|
|
7
|
+
options,
|
|
8
|
+
});
|
|
9
|
+
const result = await executeCommandBe.call(this, received, el => el.isEnabled(), options);
|
|
10
|
+
await options.afterAssertion?.({
|
|
11
|
+
matcherName: 'toBeEnabled',
|
|
12
|
+
options,
|
|
13
|
+
result
|
|
14
|
+
});
|
|
15
|
+
return result;
|
|
5
16
|
}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { executeCommandBe, aliasFn } from '../../utils.js';
|
|
2
|
-
|
|
2
|
+
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
3
|
+
export async function toExist(received, options = DEFAULT_OPTIONS) {
|
|
3
4
|
this.expectation = this.expectation || 'exist';
|
|
4
5
|
this.verb = this.verb || '';
|
|
5
|
-
|
|
6
|
+
await options.beforeAssertion?.({
|
|
7
|
+
matcherName: 'toExist',
|
|
8
|
+
options,
|
|
9
|
+
});
|
|
10
|
+
const result = await executeCommandBe.call(this, received, async (el) => {
|
|
6
11
|
try {
|
|
7
12
|
return el.isExisting();
|
|
8
13
|
}
|
|
@@ -10,6 +15,12 @@ export function toExist(received, options = {}) {
|
|
|
10
15
|
return false;
|
|
11
16
|
}
|
|
12
17
|
}, options);
|
|
18
|
+
await options.afterAssertion?.({
|
|
19
|
+
matcherName: 'toExist',
|
|
20
|
+
options,
|
|
21
|
+
result
|
|
22
|
+
});
|
|
23
|
+
return result;
|
|
13
24
|
}
|
|
14
25
|
export function toBeExisting(el, options) {
|
|
15
26
|
return aliasFn.call(this, toExist, { verb: 'be', expectation: 'existing' }, el, options);
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { executeCommandBe } from '../../utils.js';
|
|
2
|
-
|
|
2
|
+
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
3
|
+
export async function toBeFocused(received, options = DEFAULT_OPTIONS) {
|
|
3
4
|
this.expectation = this.expectation || 'focused';
|
|
4
|
-
|
|
5
|
+
await options.beforeAssertion?.({
|
|
6
|
+
matcherName: 'toBeFocused',
|
|
7
|
+
options,
|
|
8
|
+
});
|
|
9
|
+
const result = await executeCommandBe.call(this, received, el => el.isFocused(), options);
|
|
10
|
+
await options.afterAssertion?.({
|
|
11
|
+
matcherName: 'toBeFocused',
|
|
12
|
+
options,
|
|
13
|
+
result
|
|
14
|
+
});
|
|
15
|
+
return result;
|
|
5
16
|
}
|
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
import { executeCommandBe } from '../../utils.js';
|
|
2
|
-
|
|
2
|
+
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
3
|
+
export async function toBeSelected(received, options = DEFAULT_OPTIONS) {
|
|
3
4
|
this.expectation = this.expectation || 'selected';
|
|
4
|
-
|
|
5
|
+
await options.beforeAssertion?.({
|
|
6
|
+
matcherName: 'toBeSelected',
|
|
7
|
+
options,
|
|
8
|
+
});
|
|
9
|
+
const result = await executeCommandBe.call(this, received, el => el.isSelected(), options);
|
|
10
|
+
await options.afterAssertion?.({
|
|
11
|
+
matcherName: 'toBeSelected',
|
|
12
|
+
options,
|
|
13
|
+
result
|
|
14
|
+
});
|
|
15
|
+
return result;
|
|
5
16
|
}
|
|
6
|
-
export function toBeChecked(el, options) {
|
|
17
|
+
export async function toBeChecked(el, options = DEFAULT_OPTIONS) {
|
|
7
18
|
this.expectation = 'checked';
|
|
8
|
-
|
|
19
|
+
await options.beforeAssertion?.({
|
|
20
|
+
matcherName: 'toBeChecked',
|
|
21
|
+
options,
|
|
22
|
+
});
|
|
23
|
+
const result = await toBeSelected.call(this, el, options);
|
|
24
|
+
await options.afterAssertion?.({
|
|
25
|
+
matcherName: 'toBeChecked',
|
|
26
|
+
options,
|
|
27
|
+
result
|
|
28
|
+
});
|
|
29
|
+
return result;
|
|
9
30
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { waitUntil, enhanceError, compareText, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils.js';
|
|
2
|
+
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
2
3
|
async function conditionAttr(el, attribute) {
|
|
3
4
|
const attr = await el.getAttribute(attribute);
|
|
4
5
|
if (typeof attr !== 'string') {
|
|
@@ -15,7 +16,7 @@ async function conditionAttrAndValue(el, attribute, value, options) {
|
|
|
15
16
|
}
|
|
16
17
|
return compareText(attr, value, options);
|
|
17
18
|
}
|
|
18
|
-
export async function
|
|
19
|
+
export async function toHaveAttributeAndValue(received, attribute, value, options = DEFAULT_OPTIONS) {
|
|
19
20
|
const isNot = this.isNot;
|
|
20
21
|
const { expectation = 'attribute', verb = 'have' } = this;
|
|
21
22
|
let el = await received;
|
|
@@ -34,7 +35,7 @@ export async function toHaveAttributeAndValueFn(received, attribute, value, opti
|
|
|
34
35
|
message: () => message
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
+
async function toHaveAttributeFn(received, attribute) {
|
|
38
39
|
const isNot = this.isNot;
|
|
39
40
|
const { expectation = 'attribute', verb = 'have' } = this;
|
|
40
41
|
let el = await received;
|
|
@@ -50,12 +51,28 @@ export async function toHaveAttributeFn(received, attribute) {
|
|
|
50
51
|
message: () => message
|
|
51
52
|
};
|
|
52
53
|
}
|
|
53
|
-
export function toHaveAttribute(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
export async function toHaveAttribute(received, attribute, value, options = DEFAULT_OPTIONS) {
|
|
55
|
+
await options.beforeAssertion?.({
|
|
56
|
+
matcherName: 'toHaveAttribute',
|
|
57
|
+
expectedValue: [attribute, value],
|
|
58
|
+
options,
|
|
59
|
+
});
|
|
60
|
+
const result = typeof value !== 'undefined'
|
|
61
|
+
? await toHaveAttributeAndValue.call(this, received, attribute, value, options)
|
|
62
|
+
: await toHaveAttributeFn.call(this, received, attribute);
|
|
63
|
+
await options.afterAssertion?.({
|
|
64
|
+
matcherName: 'toHaveAttribute',
|
|
65
|
+
expectedValue: [attribute, value],
|
|
66
|
+
options,
|
|
67
|
+
result
|
|
68
|
+
});
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
export function toHaveAttributeContaining(el, attribute, value, options = DEFAULT_OPTIONS) {
|
|
72
|
+
return toHaveAttributeAndValue.call(this, el, attribute, value, {
|
|
73
|
+
...options,
|
|
74
|
+
containing: true
|
|
75
|
+
});
|
|
60
76
|
}
|
|
77
|
+
export const toHaveAttrContaining = toHaveAttributeContaining;
|
|
61
78
|
export const toHaveAttr = toHaveAttribute;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { waitUntil, enhanceError, compareNumbers, numberError, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils.js';
|
|
2
|
+
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
2
3
|
async function condition(el, options) {
|
|
3
4
|
const children = await el.$$('./*');
|
|
4
5
|
if (typeof options.lte !== 'number' &&
|
|
@@ -14,12 +15,17 @@ async function condition(el, options) {
|
|
|
14
15
|
value: children?.length
|
|
15
16
|
};
|
|
16
17
|
}
|
|
17
|
-
export async function toHaveChildren(received,
|
|
18
|
+
export async function toHaveChildren(received, expectedValue, options = DEFAULT_OPTIONS) {
|
|
18
19
|
const isNot = this.isNot;
|
|
19
20
|
const { expectation = 'children', verb = 'have' } = this;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
await options.beforeAssertion?.({
|
|
22
|
+
matcherName: 'toHaveChildren',
|
|
23
|
+
expectedValue,
|
|
24
|
+
options,
|
|
25
|
+
});
|
|
26
|
+
const numberOptions = typeof expectedValue === 'number'
|
|
27
|
+
? { eq: expectedValue }
|
|
28
|
+
: expectedValue || {};
|
|
23
29
|
let el = await received;
|
|
24
30
|
let children;
|
|
25
31
|
const pass = await waitUntil(async () => {
|
|
@@ -32,8 +38,15 @@ export async function toHaveChildren(received, expected, options = {}) {
|
|
|
32
38
|
const error = numberError(numberOptions);
|
|
33
39
|
const expectedArray = wrapExpectedWithArray(el, children, error);
|
|
34
40
|
const message = enhanceError(el, expectedArray, children, this, verb, expectation, '', numberOptions);
|
|
35
|
-
|
|
41
|
+
const result = {
|
|
36
42
|
pass,
|
|
37
43
|
message: () => message
|
|
38
44
|
};
|
|
45
|
+
await options.afterAssertion?.({
|
|
46
|
+
matcherName: 'toHaveChildren',
|
|
47
|
+
expectedValue,
|
|
48
|
+
options,
|
|
49
|
+
result
|
|
50
|
+
});
|
|
51
|
+
return result;
|
|
39
52
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { toHaveAttributeAndValue } from './toHaveAttribute.js';
|
|
1
2
|
import { waitUntil, enhanceError, executeCommand, wrapExpectedWithArray, updateElementsArray, compareText } from '../../utils.js';
|
|
3
|
+
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
2
4
|
async function condition(el, attribute, value, options) {
|
|
3
5
|
const { ignoreCase = false, trim = false, containing = false } = options;
|
|
4
6
|
let attr = await el.getAttribute(attribute);
|
|
@@ -27,25 +29,46 @@ async function condition(el, attribute, value, options) {
|
|
|
27
29
|
result: valueInClasses
|
|
28
30
|
};
|
|
29
31
|
}
|
|
30
|
-
export function
|
|
31
|
-
return
|
|
32
|
+
export function toHaveClass(...args) {
|
|
33
|
+
return toHaveElementClass.call(this || {}, ...args);
|
|
32
34
|
}
|
|
33
|
-
export async function
|
|
35
|
+
export async function toHaveElementClass(received, expectedValue, options = DEFAULT_OPTIONS) {
|
|
34
36
|
const isNot = this.isNot;
|
|
35
37
|
const { expectation = 'class', verb = 'have' } = this;
|
|
38
|
+
await options.beforeAssertion?.({
|
|
39
|
+
matcherName: 'toHaveElementClass',
|
|
40
|
+
expectedValue,
|
|
41
|
+
options,
|
|
42
|
+
});
|
|
36
43
|
const attribute = 'class';
|
|
37
44
|
let el = await received;
|
|
38
45
|
let attr;
|
|
39
46
|
const pass = await waitUntil(async () => {
|
|
40
|
-
const result = await executeCommand.call(this, el, condition, options, [attribute,
|
|
47
|
+
const result = await executeCommand.call(this, el, condition, options, [attribute, expectedValue, options]);
|
|
41
48
|
el = result.el;
|
|
42
49
|
attr = result.values;
|
|
43
50
|
return result.success;
|
|
44
51
|
}, isNot, options);
|
|
45
52
|
updateElementsArray(pass, received, el);
|
|
46
|
-
const message = enhanceError(el, wrapExpectedWithArray(el, attr,
|
|
47
|
-
|
|
53
|
+
const message = enhanceError(el, wrapExpectedWithArray(el, attr, expectedValue), attr, this, verb, expectation, '', options);
|
|
54
|
+
const result = {
|
|
48
55
|
pass,
|
|
49
56
|
message: () => message
|
|
50
57
|
};
|
|
58
|
+
await options.afterAssertion?.({
|
|
59
|
+
matcherName: 'toHaveElementClass',
|
|
60
|
+
expectedValue,
|
|
61
|
+
options,
|
|
62
|
+
result
|
|
63
|
+
});
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
export function toHaveElementClassContaining(...args) {
|
|
67
|
+
return toHaveClassContaining.call(this, ...args);
|
|
68
|
+
}
|
|
69
|
+
export function toHaveClassContaining(el, className, options = DEFAULT_OPTIONS) {
|
|
70
|
+
return toHaveAttributeAndValue.call(this, el, 'class', className, {
|
|
71
|
+
...options,
|
|
72
|
+
containing: true
|
|
73
|
+
});
|
|
51
74
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { waitUntil, enhanceError, compareText, compareTextWithArray, executeCommand, wrapExpectedWithArray, updateElementsArray, } from '../../utils.js';
|
|
2
|
+
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
2
3
|
async function condition(el, label, options) {
|
|
3
4
|
const actualLabel = await el.getComputedLabel();
|
|
4
5
|
if (Array.isArray(label)) {
|
|
@@ -6,21 +7,39 @@ async function condition(el, label, options) {
|
|
|
6
7
|
}
|
|
7
8
|
return compareText(actualLabel, label, options);
|
|
8
9
|
}
|
|
9
|
-
export async function toHaveComputedLabel(received,
|
|
10
|
+
export async function toHaveComputedLabel(received, expectedValue, options = DEFAULT_OPTIONS) {
|
|
10
11
|
const isNot = this.isNot;
|
|
11
12
|
const { expectation = 'computed label', verb = 'have' } = this;
|
|
13
|
+
await options.beforeAssertion?.({
|
|
14
|
+
matcherName: 'toHaveComputedLabel',
|
|
15
|
+
expectedValue,
|
|
16
|
+
options,
|
|
17
|
+
});
|
|
12
18
|
let el = await received;
|
|
13
19
|
let actualLabel;
|
|
14
20
|
const pass = await waitUntil(async () => {
|
|
15
|
-
const result = await executeCommand.call(this, el, condition, options, [
|
|
21
|
+
const result = await executeCommand.call(this, el, condition, options, [expectedValue, options]);
|
|
16
22
|
el = result.el;
|
|
17
23
|
actualLabel = result.values;
|
|
18
24
|
return result.success;
|
|
19
25
|
}, isNot, options);
|
|
20
26
|
updateElementsArray(pass, received, el);
|
|
21
|
-
const message = enhanceError(el, wrapExpectedWithArray(el, actualLabel,
|
|
22
|
-
|
|
27
|
+
const message = enhanceError(el, wrapExpectedWithArray(el, actualLabel, expectedValue), actualLabel, this, verb, expectation, '', options);
|
|
28
|
+
const result = {
|
|
23
29
|
pass,
|
|
24
|
-
message: () => message
|
|
30
|
+
message: () => message
|
|
25
31
|
};
|
|
32
|
+
await options.afterAssertion?.({
|
|
33
|
+
matcherName: 'toHaveComputedLabel',
|
|
34
|
+
expectedValue,
|
|
35
|
+
options,
|
|
36
|
+
result
|
|
37
|
+
});
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
export function toHaveComputedLabelContaining(el, label, options = DEFAULT_OPTIONS) {
|
|
41
|
+
return toHaveComputedLabel.call(this, el, label, {
|
|
42
|
+
...options,
|
|
43
|
+
containing: true
|
|
44
|
+
});
|
|
26
45
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { waitUntil, enhanceError, compareText, compareTextWithArray, executeCommand, wrapExpectedWithArray, updateElementsArray, } from '../../utils.js';
|
|
2
|
+
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
2
3
|
async function condition(el, role, options) {
|
|
3
4
|
const actualRole = await el.getComputedRole();
|
|
4
5
|
if (Array.isArray(role)) {
|
|
@@ -6,21 +7,39 @@ async function condition(el, role, options) {
|
|
|
6
7
|
}
|
|
7
8
|
return compareText(actualRole, role, options);
|
|
8
9
|
}
|
|
9
|
-
export async function toHaveComputedRole(received,
|
|
10
|
+
export async function toHaveComputedRole(received, expectedValue, options = DEFAULT_OPTIONS) {
|
|
10
11
|
const isNot = this.isNot;
|
|
11
12
|
const { expectation = 'computed role', verb = 'have' } = this;
|
|
13
|
+
await options.beforeAssertion?.({
|
|
14
|
+
matcherName: 'toHaveComputedRole',
|
|
15
|
+
expectedValue,
|
|
16
|
+
options,
|
|
17
|
+
});
|
|
12
18
|
let el = await received;
|
|
13
19
|
let actualRole;
|
|
14
20
|
const pass = await waitUntil(async () => {
|
|
15
|
-
const result = await executeCommand.call(this, el, condition, options, [
|
|
21
|
+
const result = await executeCommand.call(this, el, condition, options, [expectedValue, options]);
|
|
16
22
|
el = result.el;
|
|
17
23
|
actualRole = result.values;
|
|
18
24
|
return result.success;
|
|
19
25
|
}, isNot, options);
|
|
20
26
|
updateElementsArray(pass, received, el);
|
|
21
|
-
const message = enhanceError(el, wrapExpectedWithArray(el, actualRole,
|
|
22
|
-
|
|
27
|
+
const message = enhanceError(el, wrapExpectedWithArray(el, actualRole, expectedValue), actualRole, this, verb, expectation, '', options);
|
|
28
|
+
const result = {
|
|
23
29
|
pass,
|
|
24
|
-
message: () => message
|
|
30
|
+
message: () => message
|
|
25
31
|
};
|
|
32
|
+
await options.afterAssertion?.({
|
|
33
|
+
matcherName: 'toHaveComputedRole',
|
|
34
|
+
expectedValue,
|
|
35
|
+
options,
|
|
36
|
+
result
|
|
37
|
+
});
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
export function toHaveComputedRoleContaining(el, role, options = DEFAULT_OPTIONS) {
|
|
41
|
+
return toHaveComputedRole.call(this, el, role, {
|
|
42
|
+
...options,
|
|
43
|
+
containing: true
|
|
44
|
+
});
|
|
26
45
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { waitUntil, enhanceError, compareText, executeCommand, wrapExpectedWithArray, updateElementsArray, } from '../../utils.js';
|
|
2
|
-
|
|
2
|
+
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
3
|
+
async function condition(el, property, value, options = DEFAULT_OPTIONS) {
|
|
3
4
|
const { asString = false } = options;
|
|
4
5
|
let prop = await el.getProperty(property);
|
|
5
6
|
if (prop === null || prop === undefined) {
|
|
@@ -14,9 +15,14 @@ async function condition(el, property, value, options = {}) {
|
|
|
14
15
|
prop = prop.toString();
|
|
15
16
|
return compareText(prop, value, options);
|
|
16
17
|
}
|
|
17
|
-
export async function toHaveElementProperty(received, property, value, options =
|
|
18
|
+
export async function toHaveElementProperty(received, property, value, options = DEFAULT_OPTIONS) {
|
|
18
19
|
const isNot = this.isNot;
|
|
19
20
|
const { expectation = 'property', verb = 'have' } = this;
|
|
21
|
+
await options.beforeAssertion?.({
|
|
22
|
+
matcherName: 'toHaveElementProperty',
|
|
23
|
+
expectedValue: [property, value],
|
|
24
|
+
options,
|
|
25
|
+
});
|
|
20
26
|
let el = await received;
|
|
21
27
|
let prop;
|
|
22
28
|
const pass = await waitUntil(async () => {
|
|
@@ -34,8 +40,15 @@ export async function toHaveElementProperty(received, property, value, options =
|
|
|
34
40
|
const expected = wrapExpectedWithArray(el, prop, value);
|
|
35
41
|
message = enhanceError(el, expected, prop, this, verb, expectation, property, options);
|
|
36
42
|
}
|
|
37
|
-
|
|
43
|
+
const result = {
|
|
38
44
|
pass,
|
|
39
|
-
message: () => message
|
|
45
|
+
message: () => message
|
|
40
46
|
};
|
|
47
|
+
await options.afterAssertion?.({
|
|
48
|
+
matcherName: 'toHaveElementProperty',
|
|
49
|
+
expectedValue: [property, value],
|
|
50
|
+
options,
|
|
51
|
+
result
|
|
52
|
+
});
|
|
53
|
+
return result;
|
|
41
54
|
}
|