expect-webdriverio 4.0.0 → 4.1.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/README.md +29 -9
- package/jasmine.d.ts +0 -1
- package/jest.d.ts +1 -1
- package/lib/constants.js +4 -0
- package/lib/index.js +14 -6
- package/lib/jasmineUtils.js +7 -17
- package/lib/matchers/browser/toHaveTitle.js +12 -23
- package/lib/matchers/browser/toHaveTitleContaining.js +3 -11
- package/lib/matchers/browser/toHaveUrl.js +12 -23
- package/lib/matchers/browser/toHaveUrlContaining.js +3 -11
- package/lib/matchers/element/toBeClickable.js +10 -21
- package/lib/matchers/element/toBeDisabled.js +3 -14
- package/lib/matchers/element/toBeDisplayed.js +10 -21
- package/lib/matchers/element/toBeDisplayedInViewport.js +10 -21
- package/lib/matchers/element/toBeEnabled.js +3 -14
- package/lib/matchers/element/toBeExisting.js +14 -27
- package/lib/matchers/element/toBeFocused.js +3 -14
- package/lib/matchers/element/toBeSelected.js +6 -19
- package/lib/matchers/element/toHaveAttribute.js +35 -46
- package/lib/matchers/element/toHaveAttributeContaining.js +4 -12
- package/lib/matchers/element/toHaveChildren.js +27 -39
- package/lib/matchers/element/toHaveClass.js +47 -0
- package/lib/matchers/element/toHaveClassContaining.js +10 -0
- package/lib/matchers/element/toHaveElementProperty.js +25 -36
- 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 +17 -28
- package/lib/matchers/element/toHaveText.js +18 -29
- 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 +16 -26
- package/lib/matchers/mock/toBeRequested.js +3 -11
- package/lib/matchers/mock/toBeRequestedTimes.js +17 -32
- package/lib/matchers/mock/toBeRequestedWith.js +30 -39
- 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 +41 -49
- package/package.json +59 -44
- package/types/expect-webdriverio.d.ts +23 -22
- package/types/jest-global.d.ts +1 -1
- package/types/standalone.d.ts +2 -2
- package/lib/addMatchers.js +0 -48
- package/lib/matchers/element/toHaveElementClass.js +0 -60
- 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 -9
package/README.md
CHANGED
|
@@ -22,21 +22,41 @@ NOTE: [WebdriverIO](https://github.com/webdriverio/webdriverio) `v5.16.11` or hi
|
|
|
22
22
|
|
|
23
23
|
## Usage
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
require('expect-webdriverio')
|
|
29
|
-
},
|
|
30
|
-
```
|
|
25
|
+
### Using WebdriverIO Testrunner
|
|
26
|
+
|
|
27
|
+
If you run your tests through the [WDIO testrunner](https://webdriver.io/docs/clioptions) no additional setup is needed. WebdriverIO initialises `expect-webdriverio` and makes `expect` available in the global scope. So you can use it directly in your tests:
|
|
31
28
|
|
|
32
|
-
In your test
|
|
33
29
|
```js
|
|
34
|
-
const $button = $('button')
|
|
35
|
-
expect($button).toBeDisplayed()
|
|
30
|
+
const $button = await $('button')
|
|
31
|
+
await expect($button).toBeDisplayed()
|
|
36
32
|
```
|
|
37
33
|
|
|
38
34
|
See more [Examples](docs/Examples.md)
|
|
39
35
|
|
|
36
|
+
### Using in a standalone script
|
|
37
|
+
|
|
38
|
+
If you embed WebdriverIO in a standalone script, make sure you import `expect-webdriverio` before you use it anywhere.
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
import { remote } from 'webdriverio'
|
|
42
|
+
import { expect } from 'expect-webdriverio'
|
|
43
|
+
|
|
44
|
+
;(async () => {
|
|
45
|
+
const browser = await remote({
|
|
46
|
+
capabilities: {
|
|
47
|
+
browserName: 'chrome'
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
await browser.url('https://webdriver.io')
|
|
52
|
+
|
|
53
|
+
const $button = await browser.$('button')
|
|
54
|
+
await expect($button).toBeDisplayed()
|
|
55
|
+
|
|
56
|
+
await browser.deleteSession()
|
|
57
|
+
})().catch(console.error)
|
|
58
|
+
```
|
|
59
|
+
|
|
40
60
|
## API
|
|
41
61
|
|
|
42
62
|
Please see [API doc](docs/API.md)
|
package/jasmine.d.ts
CHANGED
package/jest.d.ts
CHANGED
package/lib/constants.js
ADDED
package/lib/index.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { expect as expectLib } from 'expect';
|
|
2
|
+
import matchers from './matchers.js';
|
|
3
|
+
import { DEFAULT_OPTIONS } from './constants.js';
|
|
4
|
+
expectLib.extend({ ...matchers });
|
|
5
|
+
export const expect = expectLib;
|
|
6
|
+
export const getConfig = () => DEFAULT_OPTIONS;
|
|
7
|
+
export const setDefaultOptions = (options = {}) => {
|
|
8
|
+
Object.entries(options).forEach(([key, value]) => {
|
|
9
|
+
if (key in DEFAULT_OPTIONS) {
|
|
10
|
+
DEFAULT_OPTIONS[key] = value;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
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,15 @@
|
|
|
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.js';
|
|
2
|
+
export async function toHaveTitle(browser, title, options = {}) {
|
|
7
3
|
const isNot = this.isNot;
|
|
8
4
|
const { expectation = 'title', verb = 'have' } = this;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
});
|
|
5
|
+
let actual;
|
|
6
|
+
const pass = await waitUntil(async () => {
|
|
7
|
+
actual = await browser.getTitle();
|
|
8
|
+
return compareText(actual, title, options).result;
|
|
9
|
+
}, isNot, options);
|
|
10
|
+
const message = enhanceError('window', title, actual, this, verb, expectation, '', options);
|
|
11
|
+
return {
|
|
12
|
+
pass,
|
|
13
|
+
message: () => message
|
|
14
|
+
};
|
|
21
15
|
}
|
|
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.js';
|
|
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,15 @@
|
|
|
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.js';
|
|
2
|
+
export async function toHaveUrl(browser, url, options = {}) {
|
|
7
3
|
const isNot = this.isNot;
|
|
8
4
|
const { expectation = 'url', verb = 'have' } = this;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
});
|
|
5
|
+
let actual;
|
|
6
|
+
const pass = await waitUntil(async () => {
|
|
7
|
+
actual = await browser.getUrl();
|
|
8
|
+
return compareText(actual, url, options).result;
|
|
9
|
+
}, isNot, options);
|
|
10
|
+
const message = enhanceError('window', url, actual, this, verb, expectation, '', options);
|
|
11
|
+
return {
|
|
12
|
+
pass,
|
|
13
|
+
message: () => message
|
|
14
|
+
};
|
|
21
15
|
}
|
|
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.js';
|
|
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,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.toBeClickable = void 0;
|
|
4
|
-
const utils_1 = require("../../utils");
|
|
5
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
function toBeClickableFn(received, options = {}) {
|
|
1
|
+
import { executeCommandBe } from '../../utils.js';
|
|
2
|
+
export function toBeClickable(received, options = {}) {
|
|
7
3
|
this.expectation = this.expectation || 'clickable';
|
|
8
|
-
return
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}, options);
|
|
17
|
-
return result;
|
|
18
|
-
});
|
|
4
|
+
return executeCommandBe.call(this, received, async (el) => {
|
|
5
|
+
try {
|
|
6
|
+
return el.isClickable();
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
}, options);
|
|
19
12
|
}
|
|
20
|
-
function toBeClickable(...args) {
|
|
21
|
-
return expectAdapter_1.runExpect.call(this, toBeClickableFn, args);
|
|
22
|
-
}
|
|
23
|
-
exports.toBeClickable = toBeClickable;
|
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.toBeDisabled = void 0;
|
|
4
|
-
const utils_1 = require("../../utils");
|
|
5
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
function toBeDisabledFn(received, options = {}) {
|
|
1
|
+
import { executeCommandBe } from '../../utils.js';
|
|
2
|
+
export function toBeDisabled(received, options = {}) {
|
|
7
3
|
this.expectation = this.expectation || 'disabled';
|
|
8
|
-
return
|
|
9
|
-
const result = await utils_1.executeCommandBe.call(this, received, async (el) => !await el.isEnabled(), options);
|
|
10
|
-
return result;
|
|
11
|
-
});
|
|
4
|
+
return executeCommandBe.call(this, received, async (el) => !await el.isEnabled(), options);
|
|
12
5
|
}
|
|
13
|
-
function toBeDisabled(...args) {
|
|
14
|
-
return expectAdapter_1.runExpect.call(this, toBeDisabledFn, args);
|
|
15
|
-
}
|
|
16
|
-
exports.toBeDisabled = toBeDisabled;
|
|
@@ -1,23 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.toBeDisplayed = void 0;
|
|
4
|
-
const utils_1 = require("../../utils");
|
|
5
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
function toBeDisplayedFn(received, options = {}) {
|
|
1
|
+
import { executeCommandBe } from '../../utils.js';
|
|
2
|
+
export async function toBeDisplayed(received, options = {}) {
|
|
7
3
|
this.expectation = this.expectation || 'displayed';
|
|
8
|
-
return
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}, options);
|
|
17
|
-
return result;
|
|
18
|
-
});
|
|
4
|
+
return executeCommandBe.call(this, received, async (el) => {
|
|
5
|
+
try {
|
|
6
|
+
return el.isDisplayed();
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
}, options);
|
|
19
12
|
}
|
|
20
|
-
function toBeDisplayed(...args) {
|
|
21
|
-
return expectAdapter_1.runExpect.call(this, toBeDisplayedFn, args);
|
|
22
|
-
}
|
|
23
|
-
exports.toBeDisplayed = toBeDisplayed;
|
|
@@ -1,23 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.toBeDisplayedInViewport = void 0;
|
|
4
|
-
const utils_1 = require("../../utils");
|
|
5
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
function toBeDisplayedInViewportFn(received, options = {}) {
|
|
1
|
+
import { executeCommandBe } from '../../utils.js';
|
|
2
|
+
export function toBeDisplayedInViewport(received, options = {}) {
|
|
7
3
|
this.expectation = this.expectation || 'displayed in viewport';
|
|
8
|
-
return
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}, options);
|
|
17
|
-
return result;
|
|
18
|
-
});
|
|
4
|
+
return executeCommandBe.call(this, received, async (el) => {
|
|
5
|
+
try {
|
|
6
|
+
return el.isDisplayedInViewport();
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
}, options);
|
|
19
12
|
}
|
|
20
|
-
function toBeDisplayedInViewport(...args) {
|
|
21
|
-
return expectAdapter_1.runExpect.call(this, toBeDisplayedInViewportFn, args);
|
|
22
|
-
}
|
|
23
|
-
exports.toBeDisplayedInViewport = toBeDisplayedInViewport;
|
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.toBeEnabled = void 0;
|
|
4
|
-
const utils_1 = require("../../utils");
|
|
5
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
function toBeEnabledFn(received, options = {}) {
|
|
1
|
+
import { executeCommandBe } from '../../utils.js';
|
|
2
|
+
export function toBeEnabled(received, options = {}) {
|
|
7
3
|
this.expectation = this.expectation || 'enabled';
|
|
8
|
-
return
|
|
9
|
-
const result = await utils_1.executeCommandBe.call(this, received, el => el.isEnabled(), options);
|
|
10
|
-
return result;
|
|
11
|
-
});
|
|
4
|
+
return executeCommandBe.call(this, received, el => el.isEnabled(), options);
|
|
12
5
|
}
|
|
13
|
-
function toBeEnabled(...args) {
|
|
14
|
-
return expectAdapter_1.runExpect.call(this, toBeEnabledFn, args);
|
|
15
|
-
}
|
|
16
|
-
exports.toBeEnabled = toBeEnabled;
|
|
@@ -1,32 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 = {}) {
|
|
1
|
+
import { executeCommandBe, aliasFn } from '../../utils.js';
|
|
2
|
+
export function toExist(received, options = {}) {
|
|
7
3
|
this.expectation = this.expectation || 'exist';
|
|
8
4
|
this.verb = this.verb || '';
|
|
9
|
-
return
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}, options);
|
|
18
|
-
return result;
|
|
19
|
-
});
|
|
5
|
+
return executeCommandBe.call(this, received, async (el) => {
|
|
6
|
+
try {
|
|
7
|
+
return el.isExisting();
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}, options);
|
|
20
13
|
}
|
|
21
|
-
function
|
|
22
|
-
return
|
|
14
|
+
export function toBeExisting(el, options) {
|
|
15
|
+
return aliasFn.call(this, toExist, { verb: 'be', expectation: 'existing' }, el, options);
|
|
23
16
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return utils_1.aliasFn.call(this, toExist, { verb: 'be', expectation: 'existing' }, el, options);
|
|
17
|
+
export function toBePresent(el, options) {
|
|
18
|
+
return aliasFn.call(this, toExist, { verb: 'be', expectation: 'present' }, el, options);
|
|
27
19
|
}
|
|
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,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.toBeFocused = void 0;
|
|
4
|
-
const utils_1 = require("../../utils");
|
|
5
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
function toBeFocusedFn(received, options = {}) {
|
|
1
|
+
import { executeCommandBe } from '../../utils.js';
|
|
2
|
+
export function toBeFocused(received, options = {}) {
|
|
7
3
|
this.expectation = this.expectation || 'focused';
|
|
8
|
-
return
|
|
9
|
-
const result = await utils_1.executeCommandBe.call(this, received, el => el.isFocused(), options);
|
|
10
|
-
return result;
|
|
11
|
-
});
|
|
4
|
+
return executeCommandBe.call(this, received, el => el.isFocused(), options);
|
|
12
5
|
}
|
|
13
|
-
function toBeFocused(...args) {
|
|
14
|
-
return expectAdapter_1.runExpect.call(this, toBeFocusedFn, args);
|
|
15
|
-
}
|
|
16
|
-
exports.toBeFocused = toBeFocused;
|
|
@@ -1,22 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 = {}) {
|
|
1
|
+
import { executeCommandBe } from '../../utils.js';
|
|
2
|
+
export function toBeSelected(received, options = {}) {
|
|
7
3
|
this.expectation = this.expectation || 'selected';
|
|
8
|
-
return
|
|
9
|
-
const result = await utils_1.executeCommandBe.call(this, received, el => el.isSelected(), options);
|
|
10
|
-
return result;
|
|
11
|
-
});
|
|
4
|
+
return executeCommandBe.call(this, received, el => el.isSelected(), options);
|
|
12
5
|
}
|
|
13
|
-
function
|
|
14
|
-
|
|
6
|
+
export function toBeChecked(el, options) {
|
|
7
|
+
this.expectation = 'checked';
|
|
8
|
+
return toBeSelected.call(this, el, options);
|
|
15
9
|
}
|
|
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;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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 { waitUntil, enhanceError, compareText, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils.js';
|
|
6
2
|
async function conditionAttr(el, attribute) {
|
|
7
3
|
const attr = await el.getAttribute(attribute);
|
|
8
4
|
if (typeof attr !== 'string') {
|
|
@@ -17,56 +13,49 @@ async function conditionAttrAndValue(el, attribute, value, options) {
|
|
|
17
13
|
if (typeof attr !== 'string') {
|
|
18
14
|
return { result: false, value: attr };
|
|
19
15
|
}
|
|
20
|
-
return
|
|
16
|
+
return compareText(attr, value, options);
|
|
21
17
|
}
|
|
22
|
-
function toHaveAttributeAndValueFn(received, attribute, value, options = {}) {
|
|
18
|
+
export async function toHaveAttributeAndValueFn(received, attribute, value, options = {}) {
|
|
23
19
|
const isNot = this.isNot;
|
|
24
20
|
const { expectation = 'attribute', verb = 'have' } = this;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
};
|
|
41
|
-
});
|
|
21
|
+
let el = await received;
|
|
22
|
+
let attr;
|
|
23
|
+
const pass = await waitUntil(async () => {
|
|
24
|
+
const result = await executeCommand.call(this, el, conditionAttrAndValue, options, [attribute, value, options]);
|
|
25
|
+
el = result.el;
|
|
26
|
+
attr = result.values;
|
|
27
|
+
return result.success;
|
|
28
|
+
}, isNot, options);
|
|
29
|
+
updateElementsArray(pass, received, el);
|
|
30
|
+
const expected = wrapExpectedWithArray(el, attr, value);
|
|
31
|
+
const message = enhanceError(el, expected, attr, this, verb, expectation, attribute, options);
|
|
32
|
+
return {
|
|
33
|
+
pass,
|
|
34
|
+
message: () => message
|
|
35
|
+
};
|
|
42
36
|
}
|
|
43
|
-
|
|
44
|
-
function toHaveAttributeFn(received, attribute) {
|
|
37
|
+
export async function toHaveAttributeFn(received, attribute) {
|
|
45
38
|
const isNot = this.isNot;
|
|
46
39
|
const { expectation = 'attribute', verb = 'have' } = this;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
};
|
|
60
|
-
});
|
|
40
|
+
let el = await received;
|
|
41
|
+
const pass = await waitUntil(async () => {
|
|
42
|
+
const result = await executeCommand.call(this, el, conditionAttr, {}, [attribute]);
|
|
43
|
+
el = result.el;
|
|
44
|
+
return result.success;
|
|
45
|
+
}, isNot, {});
|
|
46
|
+
updateElementsArray(pass, received, el);
|
|
47
|
+
const message = enhanceError(el, !isNot, pass, this, verb, expectation, attribute, {});
|
|
48
|
+
return {
|
|
49
|
+
pass,
|
|
50
|
+
message: () => message
|
|
51
|
+
};
|
|
61
52
|
}
|
|
62
|
-
|
|
63
|
-
function toHaveAttribute(...args) {
|
|
53
|
+
export function toHaveAttribute(...args) {
|
|
64
54
|
if (args.length === 3 || args.length === 4) {
|
|
65
|
-
return
|
|
55
|
+
return toHaveAttributeAndValueFn.call(this, ...args);
|
|
66
56
|
}
|
|
67
57
|
else {
|
|
68
|
-
return
|
|
58
|
+
return toHaveAttributeFn.call(this, ...args);
|
|
69
59
|
}
|
|
70
60
|
}
|
|
71
|
-
|
|
72
|
-
exports.toHaveAttr = toHaveAttribute;
|
|
61
|
+
export const toHaveAttr = toHaveAttribute;
|