expect-webdriverio 3.4.0 → 4.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/jest.d.ts +1 -1
  2. package/lib/constants.js +4 -0
  3. package/lib/index.js +15 -6
  4. package/lib/jasmineUtils.js +7 -17
  5. package/lib/matchers/browser/toHaveTitle.js +5 -14
  6. package/lib/matchers/browser/toHaveTitleContaining.js +3 -11
  7. package/lib/matchers/browser/toHaveUrl.js +5 -14
  8. package/lib/matchers/browser/toHaveUrlContaining.js +3 -11
  9. package/lib/matchers/element/toBeClickable.js +5 -12
  10. package/lib/matchers/element/toBeDisabled.js +4 -11
  11. package/lib/matchers/element/toBeDisplayed.js +5 -12
  12. package/lib/matchers/element/toBeDisplayedInViewport.js +5 -12
  13. package/lib/matchers/element/toBeEnabled.js +4 -11
  14. package/lib/matchers/element/toBeExisting.js +9 -18
  15. package/lib/matchers/element/toBeFocused.js +4 -11
  16. package/lib/matchers/element/toBeSelected.js +7 -16
  17. package/lib/matchers/element/toHaveAttribute.js +18 -24
  18. package/lib/matchers/element/toHaveAttributeContaining.js +4 -12
  19. package/lib/matchers/element/toHaveChildren.js +12 -19
  20. package/lib/matchers/element/{toHaveElementClass.js → toHaveClass.js} +10 -19
  21. package/lib/matchers/element/toHaveClassContaining.js +10 -0
  22. package/lib/matchers/element/toHaveElementProperty.js +10 -18
  23. package/lib/matchers/element/toHaveHref.js +4 -13
  24. package/lib/matchers/element/toHaveHrefContaining.js +4 -12
  25. package/lib/matchers/element/toHaveId.js +3 -12
  26. package/lib/matchers/element/toHaveStyle.js +8 -16
  27. package/lib/matchers/element/toHaveText.js +9 -17
  28. package/lib/matchers/element/toHaveTextContaining.js +3 -11
  29. package/lib/matchers/element/toHaveValue.js +3 -12
  30. package/lib/matchers/element/toHaveValueContaining.js +3 -11
  31. package/lib/matchers/elements/toBeElementsArrayOfSize.js +10 -17
  32. package/lib/matchers/mock/toBeRequested.js +3 -11
  33. package/lib/matchers/mock/toBeRequestedTimes.js +8 -16
  34. package/lib/matchers/mock/toBeRequestedWith.js +13 -19
  35. package/lib/matchers.js +62 -35
  36. package/lib/types.js +1 -0
  37. package/lib/util/elementsUtil.js +2 -7
  38. package/lib/util/executeCommand.js +3 -7
  39. package/lib/util/formatMessage.js +17 -26
  40. package/lib/util/refetchElements.js +2 -8
  41. package/lib/utils.js +15 -32
  42. package/package.json +51 -42
  43. package/types/expect-webdriverio.d.ts +1 -0
  44. package/types/jest-global.d.ts +1 -1
  45. package/types/standalone.d.ts +1 -1
  46. package/jasmine.d.ts +0 -6
  47. package/lib/addMatchers.js +0 -48
  48. package/lib/matchers/element/toHaveElementClassContaining.js +0 -20
  49. package/lib/matchers/mock/toBeRequestedWithResponse.js +0 -13
  50. package/lib/options.js +0 -33
  51. package/lib/util/expectAdapter.js +0 -41
  52. package/types/standalone-global.d.ts +0 -12
@@ -1,14 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateElementsArray = exports.wrapExpectedWithArray = void 0;
4
- const wrapExpectedWithArray = (el, actual, expected) => {
1
+ export const wrapExpectedWithArray = (el, actual, expected) => {
5
2
  if (Array.isArray(el) && el.length > 1 && Array.isArray(actual)) {
6
3
  expected = [expected];
7
4
  }
8
5
  return expected;
9
6
  };
10
- exports.wrapExpectedWithArray = wrapExpectedWithArray;
11
- const updateElementsArray = (success, received, refetched, full = false) => {
7
+ export const updateElementsArray = (success, received, refetched, full = false) => {
12
8
  if (!success) {
13
9
  return;
14
10
  }
@@ -25,4 +21,3 @@ const updateElementsArray = (success, received, refetched, full = false) => {
25
21
  }
26
22
  }
27
23
  };
28
- exports.updateElementsArray = updateElementsArray;
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.executeCommand = void 0;
4
- const refetchElements_1 = require("./refetchElements");
5
- async function executeCommand(el, condition, options = {}, params = [], fullRefetch = false) {
1
+ import { refetchElements } from './refetchElements.js';
2
+ export async function executeCommand(el, condition, options = {}, params = [], fullRefetch = false) {
6
3
  const { isNot = false } = this;
7
4
  let elements;
8
5
  if (Array.isArray(el)) {
9
- elements = await (0, refetchElements_1.refetchElements)(el, options.wait, fullRefetch);
6
+ elements = await refetchElements(el, options.wait, fullRefetch);
10
7
  }
11
8
  else {
12
9
  elements = [el];
@@ -28,4 +25,3 @@ async function executeCommand(el, condition, options = {}, params = [], fullRefe
28
25
  values: values.length > 1 ? values : values[0]
29
26
  };
30
27
  }
31
- exports.executeCommand = executeCommand;
@@ -1,46 +1,40 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.numberError = exports.enhanceErrorBe = exports.enhanceError = exports.not = exports.getSelectors = exports.getSelector = void 0;
4
- const jest_matcher_utils_1 = require("jest-matcher-utils");
5
- const jasmineUtils_1 = require("../jasmineUtils");
1
+ import { printExpected, printReceived, printDiffOrStringify } from 'jest-matcher-utils';
2
+ import { equals } from '../jasmineUtils.js';
6
3
  const EXPECTED_LABEL = 'Expected';
7
4
  const RECEIVED_LABEL = 'Received';
8
5
  const NOT_SUFFIX = ' [not]';
9
6
  const NOT_EXPECTED_LABEL = EXPECTED_LABEL + NOT_SUFFIX;
10
- const getSelector = (el) => {
7
+ export const getSelector = (el) => {
11
8
  let result = typeof el.selector === 'string' ? el.selector : '<fn>';
12
9
  if (Array.isArray(el) && el.props.length > 0) {
13
10
  result += ', <props>';
14
11
  }
15
12
  return result;
16
13
  };
17
- exports.getSelector = getSelector;
18
- const getSelectors = (el) => {
14
+ export const getSelectors = (el) => {
19
15
  const selectors = [];
20
16
  let parent;
21
17
  if (Array.isArray(el)) {
22
- selectors.push(`${el.foundWith}(\`${(0, exports.getSelector)(el)}\`)`);
18
+ selectors.push(`${el.foundWith}(\`${getSelector(el)}\`)`);
23
19
  parent = el.parent;
24
20
  }
25
21
  else {
26
22
  parent = el;
27
23
  }
28
24
  while (parent && 'selector' in parent) {
29
- const selector = (0, exports.getSelector)(parent);
25
+ const selector = getSelector(parent);
30
26
  const index = parent.index ? `[${parent.index}]` : '';
31
27
  selectors.push(`${parent.index ? '$' : ''}$(\`${selector}\`)${index}`);
32
28
  parent = parent.parent;
33
29
  }
34
30
  return selectors.reverse().join('.');
35
31
  };
36
- exports.getSelectors = getSelectors;
37
- const not = (isNot) => {
32
+ export const not = (isNot) => {
38
33
  return `${isNot ? 'not ' : ''}`;
39
34
  };
40
- exports.not = not;
41
- const enhanceError = (subject, expected, actual, context, verb, expectation, arg2 = '', { message = '', containing = false }) => {
35
+ export const enhanceError = (subject, expected, actual, context, verb, expectation, arg2 = '', { message = '', containing = false }) => {
42
36
  const { isNot = false } = context;
43
- subject = typeof subject === 'string' ? subject : (0, exports.getSelectors)(subject);
37
+ subject = typeof subject === 'string' ? subject : getSelectors(subject);
44
38
  let contain = '';
45
39
  if (containing) {
46
40
  contain = ' containing';
@@ -49,12 +43,12 @@ const enhanceError = (subject, expected, actual, context, verb, expectation, arg
49
43
  verb += ' ';
50
44
  }
51
45
  let diffString;
52
- if (isNot && (0, jasmineUtils_1.equals)(actual, expected)) {
53
- diffString = `${EXPECTED_LABEL}: ${(0, jest_matcher_utils_1.printExpected)(expected)}\n` +
54
- `${RECEIVED_LABEL}: ${(0, jest_matcher_utils_1.printReceived)(actual)}`;
46
+ if (isNot && equals(actual, expected)) {
47
+ diffString = `${EXPECTED_LABEL}: ${printExpected(expected)}\n` +
48
+ `${RECEIVED_LABEL}: ${printReceived(actual)}`;
55
49
  }
56
50
  else {
57
- diffString = (0, jest_matcher_utils_1.printDiffOrStringify)(expected, actual, EXPECTED_LABEL, RECEIVED_LABEL, true);
51
+ diffString = printDiffOrStringify(expected, actual, EXPECTED_LABEL, RECEIVED_LABEL, true);
58
52
  }
59
53
  if (isNot) {
60
54
  diffString = diffString
@@ -67,15 +61,13 @@ const enhanceError = (subject, expected, actual, context, verb, expectation, arg
67
61
  if (arg2) {
68
62
  arg2 = ` ${arg2}`;
69
63
  }
70
- const msg = `${message}Expect ${subject} ${(0, exports.not)(isNot)}to ${verb}${expectation}${arg2}${contain}\n\n${diffString}`;
64
+ const msg = `${message}Expect ${subject} ${not(isNot)}to ${verb}${expectation}${arg2}${contain}\n\n${diffString}`;
71
65
  return msg;
72
66
  };
73
- exports.enhanceError = enhanceError;
74
- const enhanceErrorBe = (subject, pass, context, verb, expectation, options) => {
75
- return (0, exports.enhanceError)(subject, (0, exports.not)(context.isNot) + expectation, (0, exports.not)(!pass) + expectation, context, verb, expectation, '', options);
67
+ export const enhanceErrorBe = (subject, pass, context, verb, expectation, options) => {
68
+ return enhanceError(subject, not(context.isNot) + expectation, not(!pass) + expectation, context, verb, expectation, '', options);
76
69
  };
77
- exports.enhanceErrorBe = enhanceErrorBe;
78
- const numberError = (options = {}) => {
70
+ export const numberError = (options = {}) => {
79
71
  if (options.eq) {
80
72
  return options.eq;
81
73
  }
@@ -90,4 +82,3 @@ const numberError = (options = {}) => {
90
82
  }
91
83
  return "no params";
92
84
  };
93
- exports.numberError = numberError;
@@ -1,10 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.refetchElements = void 0;
4
- const options_1 = require("../options");
5
- const config = (0, options_1.getConfig)();
6
- const { options: DEFAULT_OPTIONS } = config;
7
- const refetchElements = async (elements, wait = DEFAULT_OPTIONS.wait, full = false) => {
1
+ import { DEFAULT_OPTIONS } from '../constants.js';
2
+ export const refetchElements = async (elements, wait = DEFAULT_OPTIONS.wait, full = false) => {
8
3
  if (elements) {
9
4
  if (wait > 0 && (elements.length === 0 || full)) {
10
5
  elements = await elements.parent[elements.foundWith](elements.selector, ...elements.props);
@@ -12,4 +7,3 @@ const refetchElements = async (elements, wait = DEFAULT_OPTIONS.wait, full = fal
12
7
  }
13
8
  return elements;
14
9
  };
15
- exports.refetchElements = refetchElements;
package/lib/utils.js CHANGED
@@ -1,18 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.aliasFn = exports.compareNumbers = exports.waitUntil = exports.executeCommandBe = exports.executeCommand = exports.numberError = exports.enhanceError = exports.wrapExpectedWithArray = exports.updateElementsArray = exports.compareStyle = exports.compareTextWithArray = exports.compareText = void 0;
4
- const options_1 = require("./options");
5
- const executeCommand_1 = require("./util/executeCommand");
6
- Object.defineProperty(exports, "executeCommand", { enumerable: true, get: function () { return executeCommand_1.executeCommand; } });
7
- const elementsUtil_1 = require("./util/elementsUtil");
8
- Object.defineProperty(exports, "wrapExpectedWithArray", { enumerable: true, get: function () { return elementsUtil_1.wrapExpectedWithArray; } });
9
- Object.defineProperty(exports, "updateElementsArray", { enumerable: true, get: function () { return elementsUtil_1.updateElementsArray; } });
10
- const formatMessage_1 = require("./util/formatMessage");
11
- Object.defineProperty(exports, "enhanceError", { enumerable: true, get: function () { return formatMessage_1.enhanceError; } });
12
- Object.defineProperty(exports, "numberError", { enumerable: true, get: function () { return formatMessage_1.numberError; } });
13
- const expectAdapter_1 = require("./util/expectAdapter");
14
- const config = (0, options_1.getConfig)();
15
- const { options: DEFAULT_OPTIONS } = config;
1
+ import { browser } from '@wdio/globals';
2
+ import { executeCommand } from './util/executeCommand.js';
3
+ import { wrapExpectedWithArray, updateElementsArray } from './util/elementsUtil.js';
4
+ import { enhanceError, enhanceErrorBe, numberError } from './util/formatMessage.js';
5
+ import { DEFAULT_OPTIONS } from './constants.js';
16
6
  const waitUntil = async (condition, isNot = false, { wait = DEFAULT_OPTIONS.wait, interval = DEFAULT_OPTIONS.interval } = {}) => {
17
7
  if (wait === 0) {
18
8
  return await condition();
@@ -41,24 +31,22 @@ const waitUntil = async (condition, isNot = false, { wait = DEFAULT_OPTIONS.wait
41
31
  return isNot;
42
32
  }
43
33
  };
44
- exports.waitUntil = waitUntil;
45
34
  async function executeCommandBe(received, command, options) {
46
35
  const { isNot, expectation, verb = 'be' } = this;
47
36
  received = await received;
48
37
  let el = received;
49
38
  const pass = await waitUntil(async () => {
50
- const result = await executeCommand_1.executeCommand.call(this, el, async (element) => ({ result: await command(element) }), options);
39
+ const result = await executeCommand.call(this, el, async (element) => ({ result: await command(element) }), options);
51
40
  el = result.el;
52
41
  return result.success;
53
42
  }, isNot, options);
54
- (0, elementsUtil_1.updateElementsArray)(pass, received, el);
55
- const message = (0, formatMessage_1.enhanceErrorBe)(el, pass, this, verb, expectation, options);
43
+ updateElementsArray(pass, received, el);
44
+ const message = enhanceErrorBe(el, pass, this, verb, expectation, options);
56
45
  return {
57
46
  pass,
58
47
  message: () => message
59
48
  };
60
49
  }
61
- exports.executeCommandBe = executeCommandBe;
62
50
  const compareNumbers = (actual, options = {}) => {
63
51
  if (typeof options.eq === 'number') {
64
52
  return actual === options.eq;
@@ -74,8 +62,7 @@ const compareNumbers = (actual, options = {}) => {
74
62
  }
75
63
  return false;
76
64
  };
77
- exports.compareNumbers = compareNumbers;
78
- const compareText = (actual, expected, { ignoreCase = false, trim = true, containing = false }) => {
65
+ export const compareText = (actual, expected, { ignoreCase = false, trim = true, containing = false }) => {
79
66
  if (typeof actual !== 'string') {
80
67
  return {
81
68
  value: actual,
@@ -108,8 +95,7 @@ const compareText = (actual, expected, { ignoreCase = false, trim = true, contai
108
95
  result: actual === expected
109
96
  };
110
97
  };
111
- exports.compareText = compareText;
112
- const compareTextWithArray = (actual, expectedArray, { ignoreCase = false, trim = false, containing = false }) => {
98
+ export const compareTextWithArray = (actual, expectedArray, { ignoreCase = false, trim = false, containing = false }) => {
113
99
  if (typeof actual !== 'string') {
114
100
  return {
115
101
  value: actual,
@@ -131,8 +117,7 @@ const compareTextWithArray = (actual, expectedArray, { ignoreCase = false, trim
131
117
  result: textInArray
132
118
  };
133
119
  };
134
- exports.compareTextWithArray = compareTextWithArray;
135
- const compareStyle = async (actualEl, style, { ignoreCase = true, trim = false }) => {
120
+ export const compareStyle = async (actualEl, style, { ignoreCase = true, trim = false }) => {
136
121
  let result = true;
137
122
  const actual = {};
138
123
  for (const key in style) {
@@ -155,11 +140,9 @@ const compareStyle = async (actualEl, style, { ignoreCase = true, trim = false }
155
140
  result
156
141
  };
157
142
  };
158
- exports.compareStyle = compareStyle;
159
143
  function aliasFn(fn, { verb, expectation } = {}, ...args) {
160
- const context = (0, expectAdapter_1.getContext)(this);
161
- context.verb = verb;
162
- context.expectation = expectation;
163
- return fn.apply(context, args);
144
+ this.verb = verb;
145
+ this.expectation = expectation;
146
+ return fn.apply(this, args);
164
147
  }
165
- exports.aliasFn = aliasFn;
148
+ export { updateElementsArray, wrapExpectedWithArray, enhanceError, numberError, executeCommand, executeCommandBe, waitUntil, compareNumbers, aliasFn, };
package/package.json CHANGED
@@ -1,68 +1,77 @@
1
1
  {
2
2
  "name": "expect-webdriverio",
3
- "version": "3.4.0",
4
- "description": "",
5
- "main": "lib/index.js",
3
+ "version": "4.0.0-alpha.2",
4
+ "author": "Mykola Grybyk <mykola.grybyk@gmail.com>",
5
+ "description": "WebdriverIO Assertion Library",
6
+ "license": "MIT",
7
+ "homepage": "https://webdriver.io",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/webdriverio/expect-webdriverio.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/webdriverio/expect-webdriverio/issues"
14
+ },
15
+ "keywords": [
16
+ "expect-webdriverio",
17
+ "expect",
18
+ "webdriverio",
19
+ "wdio"
20
+ ],
21
+ "main": "./lib/index.cjs.js",
22
+ "type": "module",
23
+ "module": "./lib/index.js",
24
+ "exports": {
25
+ ".": [
26
+ {
27
+ "import": "./lib/index.js",
28
+ "require": "./lib/index.cjs.js"
29
+ },
30
+ "./lib/index.cjs.js"
31
+ ]
32
+ },
33
+ "types": "types/jest-global.d.ts",
34
+ "typeScriptVersion": "3.8.3",
6
35
  "scripts": {
7
36
  "build": "run-s clean compile",
8
37
  "clean": "run-p clean:*",
9
38
  "clean:build": "rimraf ./lib",
10
39
  "clean:tests": "rimraf test-types/**/node_modules && rimraf test-types/**/dist",
11
40
  "compile": "tsc --build tsconfig.build.json",
12
- "release": "release-it --github.release",
13
- "release:ci": "npm run release -- --ci --npm.skipChecks --no-git.requireCleanWorkingDir",
14
- "release:patch": "npm run release -- patch",
15
- "release:minor": "npm run release -- minor",
16
- "release:major": "npm run release -- major",
17
41
  "test": "run-s test:*",
18
42
  "test:lint": "eslint . --ext .js,.jsx,.ts,.tsx",
19
- "test:unit": "jest",
20
- "watch": "npm run compile -- --watch",
43
+ "test:unit": "vitest",
21
44
  "test:types": "node test-types/copy && npm run ts && npm run clean:tests",
22
45
  "ts": "run-p ts:*",
23
46
  "ts:default": "cd test-types/default && tsc --incremental",
24
47
  "ts:jest": "cd test-types/jest && tsc --incremental",
25
48
  "ts:jasmine": "cd test-types/jasmine && tsc --incremental",
49
+ "watch": "npm run compile -- --watch",
26
50
  "prepare": "husky install"
27
51
  },
28
- "repository": {
29
- "type": "git",
30
- "url": "git+https://github.com/webdriverio/expect-webdriverio.git"
31
- },
32
- "keywords": [
33
- "expect-webdriverio",
34
- "expect",
35
- "webdriverio",
36
- "wdio"
37
- ],
38
- "author": "Mykola Grybyk <mykola.grybyk@gmail.com>",
39
- "license": "MIT",
40
- "bugs": {
41
- "url": "https://github.com/webdriverio/expect-webdriverio/issues"
42
- },
43
- "homepage": "https://github.com/webdriverio/expect-webdriverio#readme",
44
52
  "devDependencies": {
45
- "@types/jasmine": "^4.0.3",
46
- "@types/jest": "^27.5.1",
47
- "@types/node": "^15.14.0",
48
- "@typescript-eslint/eslint-plugin": "^5.23.0",
49
- "@typescript-eslint/parser": "^5.23.0",
50
- "eslint": "^8.15.0",
53
+ "@types/jest": "^28.1.6",
54
+ "@types/node": "^18.7.1",
55
+ "@typescript-eslint/eslint-plugin": "^5.33.0",
56
+ "@typescript-eslint/parser": "^5.33.0",
57
+ "c8": "^7.12.0",
58
+ "eslint": "^8.21.0",
59
+ "eslint-plugin-import": "^2.26.0",
60
+ "eslint-plugin-unicorn": "^43.0.2",
51
61
  "husky": "^8.0.1",
52
- "jest": "^28.1.0",
53
62
  "npm-run-all": "^4.1.5",
54
- "release-it": "^15.0.0",
63
+ "release-it": "^15.3.0",
55
64
  "rimraf": "^3.0.2",
56
65
  "shelljs": "^0.8.5",
57
- "ts-jest": "^28.0.2",
58
- "ts-node": "^10.7.0",
59
- "typescript": "^4.6.4",
60
- "webdriverio": "^7.19.7"
66
+ "typescript": "^4.7.4",
67
+ "vitest": "0.21.1"
68
+ },
69
+ "peerDependencies": {
70
+ "@wdio/globals": "next",
71
+ "webdriverio": "next"
61
72
  },
62
- "types": "types/jest-global.d.ts",
63
- "typeScriptVersion": "3.8.3",
64
73
  "dependencies": {
65
- "expect": "^28.1.0",
66
- "jest-matcher-utils": "^28.1.0"
74
+ "expect": "^28.1.3",
75
+ "jest-matcher-utils": "^28.1.3"
67
76
  }
68
77
  }
@@ -1,4 +1,5 @@
1
1
  declare namespace ExpectWebdriverIO {
2
+ function expect<T = unknown>(actual: T): Matchers<T, T>
2
3
  function setOptions(options: DefaultOptions): void
3
4
 
4
5
  interface DefaultOptions {
@@ -1,4 +1,4 @@
1
- /// <reference types="expect-webdriverio/types/standalone"/>
1
+ /// <reference types="./standalone"/>
2
2
 
3
3
  declare const expect: ExpectWebdriverIO.Expect
4
4
 
@@ -1,4 +1,4 @@
1
- /// <reference types="expect-webdriverio/types/expect-webdriverio"/>
1
+ /// <reference types="./expect-webdriverio"/>
2
2
 
3
3
  declare namespace ExpectWebdriverIO {
4
4
  interface Matchers<R, T> extends Readonly<import('expect').Matchers<R>> {
package/jasmine.d.ts DELETED
@@ -1,6 +0,0 @@
1
- /// <reference types="expect-webdriverio/types/expect-webdriverio"/>
2
-
3
- declare module jasmine {
4
- interface Matchers<T> extends ExpectWebdriverIO.Matchers<any, T> {}
5
- interface AsyncMatchers<T, U> extends ExpectWebdriverIO.Matchers<Promise<void>, T> {}
6
- }
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addMatchers = exports.loadExpect = exports.isJasmine = void 0;
4
- let expectLib;
5
- const isJasmine = () => {
6
- return Boolean(global.jasmine && global.expect && global.expectAsync && global.jasmine.getEnv && global.jasmine.addMatchers && global.jasmine.addAsyncMatchers);
7
- };
8
- exports.isJasmine = isJasmine;
9
- const loadExpect = () => {
10
- try {
11
- return expectLib = require('expect').expect;
12
- }
13
- catch (err) {
14
- return console.error('Failed to load expect package. Make sure it has been installed: npm i expect');
15
- }
16
- };
17
- exports.loadExpect = loadExpect;
18
- const addMatchers = () => {
19
- if (global.expect === undefined) {
20
- if (!(0, exports.loadExpect)()) {
21
- return;
22
- }
23
- global.expect = expectLib;
24
- }
25
- else {
26
- expectLib = global.expect;
27
- }
28
- if (!global.expect.extend && !(0, exports.isJasmine)()) {
29
- if (!(0, exports.loadExpect)()) {
30
- return;
31
- }
32
- global.expectWdio = expectLib;
33
- console.warn('Warning! Unsupported expect lib is used.\n' +
34
- "Only Jasmine >= 3.3.0 and Jest's expect are supported.\n" +
35
- "expect-webdriverio is assigned to global.expectWdio");
36
- }
37
- require('./options').setDefaultOptions;
38
- const matchers = require('./matchers').default;
39
- if (expectLib.extend) {
40
- return expectLib.extend({ ...matchers });
41
- }
42
- expectLib = global.jasmine;
43
- return expectLib.getEnv().beforeAll(function addExpectWebdriverIOMatchers() {
44
- expectLib.addMatchers({ ...matchers });
45
- expectLib.addAsyncMatchers({ ...matchers });
46
- });
47
- };
48
- exports.addMatchers = addMatchers;
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toHaveClassContaining = exports.toHaveElementClassContaining = void 0;
4
- const expectAdapter_1 = require("../../util/expectAdapter");
5
- const toHaveAttribute_1 = require("./toHaveAttribute");
6
- function toHaveElementClassContainingFn(el, className, options = {}) {
7
- return toHaveAttribute_1.toHaveAttributeAndValueFn.call(this, el, 'class', className, {
8
- ...options,
9
- containing: true
10
- });
11
- }
12
- function toHaveElementClassContaining(...args) {
13
- return expectAdapter_1.runExpect.call(this || {}, toHaveElementClassContainingFn, args);
14
- }
15
- exports.toHaveElementClassContaining = toHaveElementClassContaining;
16
- function toHaveClassContaining(...args) {
17
- console.warn('expect(...).toHaveClassContaining is deprecated and will be removed in next release. Use toHaveElementClassContaining instead.');
18
- return expectAdapter_1.runExpect.call(this || {}, toHaveElementClassContainingFn, args);
19
- }
20
- exports.toHaveClassContaining = toHaveClassContaining;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toBeRequestedWithResponse = void 0;
4
- const toBeRequestedWith_1 = require("./toBeRequestedWith");
5
- const expectAdapter_1 = require("../../util/expectAdapter");
6
- function toBeRequestedWithResponseFn(received, response, options = {}) {
7
- return toBeRequestedWith_1.toBeRequestedWithFn.call(this, received, { response }, options);
8
- }
9
- function toBeRequestedWithResponse(...args) {
10
- console.warn('expect(...).toBeRequestedWithResponse is deprecated and will be removed in next release. Use toBeRequestedWith instead.');
11
- return expectAdapter_1.runExpect.call(this || {}, toBeRequestedWithResponseFn, args);
12
- }
13
- exports.toBeRequestedWithResponse = toBeRequestedWithResponse;
package/lib/options.js DELETED
@@ -1,33 +0,0 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.setDefaultOptions = exports.getConfig = void 0;
5
- const DEFAULT_OPTIONS = {
6
- wait: 2000,
7
- interval: 100,
8
- };
9
- let mode = 'jest';
10
- let expectLib;
11
- if (global.expectWdio) {
12
- expectLib = global.expectWdio;
13
- }
14
- else if (global.jasmine && !((_a = global.expect) === null || _a === void 0 ? void 0 : _a.extend)) {
15
- expectLib = global.jasmine;
16
- mode = 'jasmine';
17
- }
18
- else {
19
- expectLib = global.expect;
20
- }
21
- if (!expectLib._expectWebdriverio) {
22
- expectLib._expectWebdriverio = { options: { ...DEFAULT_OPTIONS }, mode };
23
- }
24
- const getConfig = () => expectLib._expectWebdriverio;
25
- exports.getConfig = getConfig;
26
- const setDefaultOptions = (options = {}) => {
27
- Object.entries(options).forEach(([key, value]) => {
28
- if (key in DEFAULT_OPTIONS) {
29
- expectLib._expectWebdriverio.options[key] = value;
30
- }
31
- });
32
- };
33
- exports.setDefaultOptions = setDefaultOptions;
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runExpect = exports.runJasmineExpect = exports.jestResultToJasmine = exports.buildJasmineFromJestResult = exports.runJestExpect = exports.getContext = void 0;
4
- const options_1 = require("../options");
5
- const config = (0, options_1.getConfig)();
6
- const { mode: MODE } = config;
7
- const getContext = (context) => global === context ? {} : context || {};
8
- exports.getContext = getContext;
9
- function runJestExpect(fn, args) {
10
- return fn.apply(this, args);
11
- }
12
- exports.runJestExpect = runJestExpect;
13
- const buildJasmineFromJestResult = (result, isNot) => {
14
- return {
15
- pass: result.pass !== isNot,
16
- message: result.message()
17
- };
18
- };
19
- exports.buildJasmineFromJestResult = buildJasmineFromJestResult;
20
- const jestResultToJasmine = (result, isNot) => {
21
- if (result instanceof Promise) {
22
- return result.then(jestStyleResult => (0, exports.buildJasmineFromJestResult)(jestStyleResult, isNot));
23
- }
24
- return (0, exports.buildJasmineFromJestResult)(result, isNot);
25
- };
26
- exports.jestResultToJasmine = jestResultToJasmine;
27
- function runJasmineExpect(fn) {
28
- const context = (0, exports.getContext)(this);
29
- return {
30
- compare(...args) {
31
- const result = fn.apply({ ...context, isNot: false }, args);
32
- return (0, exports.jestResultToJasmine)(result, false);
33
- },
34
- negativeCompare(...args) {
35
- const result = fn.apply({ ...context, isNot: true }, args);
36
- return (0, exports.jestResultToJasmine)(result, true);
37
- }
38
- };
39
- }
40
- exports.runJasmineExpect = runJasmineExpect;
41
- exports.runExpect = MODE === 'jasmine' ? runJasmineExpect : runJestExpect;
@@ -1,12 +0,0 @@
1
- /// <reference types="expect-webdriverio/types/standalone"/>
2
-
3
- /**
4
- * to use as an additional expectation lib (not recommended)
5
- */
6
- declare const expectWdio: ExpectWebdriverIO.Expect
7
-
8
- declare namespace NodeJS {
9
- interface Global {
10
- expectWdio: ExpectWebdriverIO.Expect;
11
- }
12
- }