expect-webdriverio 6.0.3 → 6.0.5

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.
@@ -0,0 +1,2 @@
1
+ import { some as wdioSome } from '../matchers/modifiers/some.js';
2
+ export const some = wdioSome;
package/lib/index.js CHANGED
@@ -4,18 +4,6 @@ import { DEFAULT_OPTIONS, defaultOptionsList } from './constants.js';
4
4
  import createSoftExpect from './softExpect.js';
5
5
  import { SoftAssertService } from './softAssert.js';
6
6
  import { oneOf } from './matchers/asymmetrics/oneOf.js';
7
- import { some as wdioSome } from './matchers/modifiers/some.js';
8
- const wdioExpect = expectLib;
9
- const MATCHERS_VERSION = '6.0.3';
10
- if ((wdioExpect.__wdio_version && wdioExpect.__wdio_version !== MATCHERS_VERSION) || (!wdioExpect.__wdio_version && wdioExpect.soft !== undefined)) {
11
- if (wdioExpect.__wdio_version) {
12
- console.warn(`[expect-webdriverio] Conflict: Initializing v${MATCHERS_VERSION}, but v${wdioExpect.__wdio_version} is already loaded.`);
13
- }
14
- else {
15
- console.warn(`[expect-webdriverio] Conflict: Initializing v${MATCHERS_VERSION}, but an older version of expect-webdriverio is already loaded.`);
16
- }
17
- }
18
- wdioExpect.__wdio_version = MATCHERS_VERSION;
19
7
  export const wdioCustomMatchers = {};
20
8
  export const matchers = new Map();
21
9
  const extend = expectLib.extend;
@@ -35,24 +23,22 @@ Object.entries(wdioMatchers).forEach(([matcher, value]) => {
35
23
  filteredWdioMatchers[matcher] = value;
36
24
  }
37
25
  });
26
+ const wdioExpect = expectLib;
38
27
  wdioExpect.extend(filteredWdioMatchers);
39
28
  wdioExpect.oneOf = oneOf;
40
- if (wdioExpect.soft === undefined) {
41
- Object.defineProperty(wdioExpect, 'soft', {
42
- value: (actual) => createSoftExpect(actual)
43
- });
44
- Object.defineProperty(wdioExpect, 'getSoftFailures', {
45
- value: (testId) => SoftAssertService.getInstance().getFailures(testId)
46
- });
47
- Object.defineProperty(wdioExpect, 'assertSoftFailures', {
48
- value: (testId) => SoftAssertService.getInstance().assertNoFailures(testId)
49
- });
50
- Object.defineProperty(wdioExpect, 'clearSoftFailures', {
51
- value: (testId) => SoftAssertService.getInstance().clearFailures(testId)
52
- });
53
- }
29
+ Object.defineProperty(wdioExpect, 'soft', {
30
+ value: (actual) => createSoftExpect(actual)
31
+ });
32
+ Object.defineProperty(wdioExpect, 'getSoftFailures', {
33
+ value: (testId) => SoftAssertService.getInstance().getFailures(testId)
34
+ });
35
+ Object.defineProperty(wdioExpect, 'assertSoftFailures', {
36
+ value: (testId) => SoftAssertService.getInstance().assertNoFailures(testId)
37
+ });
38
+ Object.defineProperty(wdioExpect, 'clearSoftFailures', {
39
+ value: (testId) => SoftAssertService.getInstance().clearFailures(testId)
40
+ });
54
41
  export const expect = wdioExpect;
55
- export const some = wdioSome;
56
42
  export const getDefaultOptions = () => DEFAULT_OPTIONS;
57
43
  export const setDefaultOptions = (options) => {
58
44
  Object.entries(options).forEach(([key, value]) => {
@@ -1,6 +1,9 @@
1
1
  import { compareTextWithArray } from '../../utils.js';
2
2
  import { WdioAsymmetricMatchers } from './asymmetricsUtils.js';
3
+ const ONE_OF_TAG = 'expect-webdriverio.oneOf';
4
+ const ONE_OF_SYMBOL = Symbol.for(ONE_OF_TAG);
3
5
  export class OneOfMatcher extends WdioAsymmetricMatchers {
6
+ [ONE_OF_SYMBOL] = true;
4
7
  options = {};
5
8
  constructor(...sample) {
6
9
  super(sample);
@@ -49,3 +52,6 @@ export class OneOfMatcher extends WdioAsymmetricMatchers {
49
52
  export function oneOf(...sample) {
50
53
  return new OneOfMatcher(...sample);
51
54
  }
55
+ export function isOneOfMatcher(oneOfMatcher) {
56
+ return oneOfMatcher instanceof OneOfMatcher || oneOfMatcher?.[ONE_OF_SYMBOL] === true;
57
+ }
@@ -3,7 +3,7 @@ import { executeCommandWithStrategy } from '../../util/executeCommand.js';
3
3
  import { compareText, enhanceError, isAsymmetricMatcher, waitUntil, wrapExpectedWithArray } from '../../utils.js';
4
4
  import { expect as wdioExpect } from '../../index.js';
5
5
  import { buildWdioAsymmetricMatchersWithOptions } from '../asymmetrics/asymmetricsUtils.js';
6
- import { OneOfMatcher } from '../asymmetrics/oneOf.js';
6
+ import { isOneOfMatcher } from '../asymmetrics/oneOf.js';
7
7
  async function conditionAttributeValueMatchWithExpected(el, attribute, expectedValue, options) {
8
8
  const attributeValue = await el.getAttribute(attribute);
9
9
  if (typeof attributeValue !== 'string' || expectedValue === undefined || expectedValue === null) {
@@ -12,7 +12,7 @@ async function conditionAttributeValueMatchWithExpected(el, attribute, expectedV
12
12
  }
13
13
  return { success: attributeValue === expectedValue, actual: attributeValue };
14
14
  }
15
- else if (expectedValue instanceof OneOfMatcher) {
15
+ else if (isOneOfMatcher(expectedValue)) {
16
16
  return { success: expectedValue.asymmetricMatch(attributeValue), actual: attributeValue };
17
17
  }
18
18
  return compareText(attributeValue, expectedValue, options);
@@ -3,7 +3,7 @@ import { executeCommandWithStrategy } from '../../util/executeCommand.js';
3
3
  import { expect as wdioExpect } from '../../index.js';
4
4
  import { compareText, enhanceError, isAsymmetricMatcher, waitUntil, wrapExpectedWithArray } from '../../utils.js';
5
5
  import { buildWdioAsymmetricMatchersWithOptions } from '../asymmetrics/asymmetricsUtils.js';
6
- import { OneOfMatcher } from '../asymmetrics/oneOf.js';
6
+ import { isOneOfMatcher } from '../asymmetrics/oneOf.js';
7
7
  async function condition(el, property, expectedValue, options = DEFAULT_OPTIONS) {
8
8
  const { asString = false } = options;
9
9
  const propertyValue = await el.getProperty(property);
@@ -13,7 +13,7 @@ async function condition(el, property, expectedValue, options = DEFAULT_OPTIONS)
13
13
  }
14
14
  return { success: propertyValue === expectedValue, actual: propertyValue };
15
15
  }
16
- else if (expectedValue instanceof OneOfMatcher) {
16
+ else if (isOneOfMatcher(expectedValue)) {
17
17
  return { success: expectedValue.asymmetricMatch(propertyValue), actual: propertyValue };
18
18
  }
19
19
  return compareText(propertyValue.toString(), expectedValue, options);
@@ -11,5 +11,5 @@ export function some(elements) {
11
11
  return new SomeElementsWrapper(elements);
12
12
  }
13
13
  export function isSomeWrapper(value) {
14
- return value instanceof SomeElementsWrapper;
14
+ return value instanceof SomeElementsWrapper || value?.[SOME_SYMBOL] === true;
15
15
  }
@@ -1 +1 @@
1
- {"root":["../src/constants.ts","../src/index.ts","../src/jasmineUtils.ts","../src/matchers.ts","../src/snapshot.ts","../src/softAssert.ts","../src/softAssertService.ts","../src/softExpect.ts","../src/types.ts","../src/utils.ts","../src/matchers/snapshot.ts","../src/matchers/asymmetrics/asymmetricsUtils.ts","../src/matchers/asymmetrics/oneOf.ts","../src/matchers/browser/toHaveClipboardText.ts","../src/matchers/browser/toHaveLocalStorageItem.ts","../src/matchers/browser/toHaveTitle.ts","../src/matchers/browser/toHaveUrl.ts","../src/matchers/element/toBeClickable.ts","../src/matchers/element/toBeDisabled.ts","../src/matchers/element/toBeDisplayed.ts","../src/matchers/element/toBeDisplayedInViewport.ts","../src/matchers/element/toBeEnabled.ts","../src/matchers/element/toBeExisting.ts","../src/matchers/element/toBeFocused.ts","../src/matchers/element/toBeSelected.ts","../src/matchers/element/toHaveAttribute.ts","../src/matchers/element/toHaveChildren.ts","../src/matchers/element/toHaveComputedLabel.ts","../src/matchers/element/toHaveComputedRole.ts","../src/matchers/element/toHaveElementClass.ts","../src/matchers/element/toHaveElementProperty.ts","../src/matchers/element/toHaveHTML.ts","../src/matchers/element/toHaveHeight.ts","../src/matchers/element/toHaveHref.ts","../src/matchers/element/toHaveId.ts","../src/matchers/element/toHaveSize.ts","../src/matchers/element/toHaveStyle.ts","../src/matchers/element/toHaveText.ts","../src/matchers/element/toHaveValue.ts","../src/matchers/element/toHaveWidth.ts","../src/matchers/elements/toBeElementsArrayOfSize.ts","../src/matchers/mock/toBeRequested.ts","../src/matchers/mock/toBeRequestedTimes.ts","../src/matchers/mock/toBeRequestedWith.ts","../src/matchers/modifiers/some.ts","../src/util/commandOptionsUtils.ts","../src/util/elementsUtil.ts","../src/util/executeCommand.ts","../src/util/formatMessage.ts","../src/util/numberOptionsUtil.ts","../src/util/refetchElements.ts","../src/util/stringUtil.ts","../src/util/waitUntil.ts"],"version":"5.9.3"}
1
+ {"root":["../src/constants.ts","../src/index.ts","../src/jasmineUtils.ts","../src/matchers.ts","../src/snapshot.ts","../src/softAssert.ts","../src/softAssertService.ts","../src/softExpect.ts","../src/types.ts","../src/utils.ts","../src/api/index.ts","../src/matchers/snapshot.ts","../src/matchers/asymmetrics/asymmetricsUtils.ts","../src/matchers/asymmetrics/oneOf.ts","../src/matchers/browser/toHaveClipboardText.ts","../src/matchers/browser/toHaveLocalStorageItem.ts","../src/matchers/browser/toHaveTitle.ts","../src/matchers/browser/toHaveUrl.ts","../src/matchers/element/toBeClickable.ts","../src/matchers/element/toBeDisabled.ts","../src/matchers/element/toBeDisplayed.ts","../src/matchers/element/toBeDisplayedInViewport.ts","../src/matchers/element/toBeEnabled.ts","../src/matchers/element/toBeExisting.ts","../src/matchers/element/toBeFocused.ts","../src/matchers/element/toBeSelected.ts","../src/matchers/element/toHaveAttribute.ts","../src/matchers/element/toHaveChildren.ts","../src/matchers/element/toHaveComputedLabel.ts","../src/matchers/element/toHaveComputedRole.ts","../src/matchers/element/toHaveElementClass.ts","../src/matchers/element/toHaveElementProperty.ts","../src/matchers/element/toHaveHTML.ts","../src/matchers/element/toHaveHeight.ts","../src/matchers/element/toHaveHref.ts","../src/matchers/element/toHaveId.ts","../src/matchers/element/toHaveSize.ts","../src/matchers/element/toHaveStyle.ts","../src/matchers/element/toHaveText.ts","../src/matchers/element/toHaveValue.ts","../src/matchers/element/toHaveWidth.ts","../src/matchers/elements/toBeElementsArrayOfSize.ts","../src/matchers/mock/toBeRequested.ts","../src/matchers/mock/toBeRequestedTimes.ts","../src/matchers/mock/toBeRequestedWith.ts","../src/matchers/modifiers/some.ts","../src/util/commandOptionsUtils.ts","../src/util/elementsUtil.ts","../src/util/executeCommand.ts","../src/util/formatMessage.ts","../src/util/numberOptionsUtil.ts","../src/util/refetchElements.ts","../src/util/stringUtil.ts","../src/util/waitUntil.ts"],"version":"5.9.3"}
package/lib/utils.js CHANGED
@@ -5,7 +5,7 @@ import { executeCommandWithStrategy } from './util/executeCommand.js';
5
5
  import { enhanceError, enhanceErrorBe } from './util/formatMessage.js';
6
6
  import { waitUntil } from './util/waitUntil.js';
7
7
  import { DEFAULT_FEATURE_FLAGS } from './constants.js';
8
- import { OneOfMatcher } from './matchers/asymmetrics/oneOf.js';
8
+ import { isOneOfMatcher, OneOfMatcher } from './matchers/asymmetrics/oneOf.js';
9
9
  export function isJasmineStringAsymmetricMatcher(expected) {
10
10
  return isAsymmetricMatcher(expected) && !('toAsymmetricMatcher' in expected) && 'jasmineToString' in expected && typeof expected.jasmineToString === 'function';
11
11
  }
@@ -88,7 +88,7 @@ export const compareTextOrArray = (actualText, expectedTexts, options) => {
88
88
  return { actual: actualText, success: false };
89
89
  }
90
90
  if (Array.isArray(expectedTexts)) {
91
- if (expectedTexts.some((expected) => expected instanceof OneOfMatcher)) {
91
+ if (expectedTexts.some((expected) => isOneOfMatcher(expected))) {
92
92
  throw new Error('OneOf is not supported in array under legacy behavior. Please enable `useToHaveTextStrictMultiElementsCompareStrategy` feature flag to use the new strict index based matching strategy with `expect.oneOf()`.');
93
93
  }
94
94
  else {
@@ -96,7 +96,7 @@ export const compareTextOrArray = (actualText, expectedTexts, options) => {
96
96
  expectedTexts = new OneOfMatcher(...expectedTexts).withOptions(options);
97
97
  }
98
98
  }
99
- if (expectedTexts instanceof OneOfMatcher) {
99
+ if (isOneOfMatcher(expectedTexts)) {
100
100
  return { success: expectedTexts.asymmetricMatch(actualText), actual: actualText };
101
101
  }
102
102
  const compareResults = compareText(actualText, expectedTexts, options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expect-webdriverio",
3
- "version": "6.0.3",
3
+ "version": "6.0.5",
4
4
  "author": "Mykola Grybyk <mykola.grybyk@gmail.com>",
5
5
  "description": "WebdriverIO Assertion Library",
6
6
  "license": "MIT",
@@ -44,7 +44,8 @@
44
44
  }
45
45
  ],
46
46
  "./types": "./types/expect-global.d.ts",
47
- "./expect-global": "./types/expect-global.d.ts"
47
+ "./expect-global": "./types/expect-global.d.ts",
48
+ "./api": "./lib/api/index.js"
48
49
  },
49
50
  "types": "./types/expect-webdriverio.d.ts",
50
51
  "typeScriptVersion": "3.8.3",
@@ -22,7 +22,6 @@ type ExpectLibExpectationResult = import('expect').ExpectationResult
22
22
  type ExpectLibMatcherContext = import('expect').MatcherContext
23
23
  type MatchersObject = Parameters<typeof import('expect').expect.extend>[0]
24
24
  type ExpectLibAnything = ReturnType<typeof expect.any> | ReturnType<typeof expect.anything>
25
-
26
25
  type WdioSome<T> = import('../src/matchers/modifiers/some.js').SomeElementsWrapper<T>
27
26
 
28
27
  // Extracted from the expect library, this is the type of the matcher function used in the expect library.
@@ -1264,7 +1263,17 @@ declare namespace ExpectWebdriverIO {
1264
1263
  * Allow to match one of the specified value.
1265
1264
  */
1266
1265
  type OneOfPartialMatcher<T> = ExpectWebdriverIO.PartialMatcher<T[]>
1266
+ }
1267
+
1268
+ declare module 'expect-webdriverio' {
1269
+ export = ExpectWebdriverIO
1270
+ }
1267
1271
 
1272
+ /**
1273
+ * Expose the expect-wdio API without the burden of initialization.
1274
+ * Required since importing from 'expect-webdriverio' can trigger double initialization.
1275
+ */
1276
+ declare module 'expect-webdriverio/api' {
1268
1277
  /**
1269
1278
  * Quantifier modifier. Wraps a `$$()` result so that the matcher passes
1270
1279
  * when at least one element satisfies the condition (∃ semantics).
@@ -1274,11 +1283,7 @@ declare namespace ExpectWebdriverIO {
1274
1283
  * await expect(some($$('.items'))).not.toBeDisplayed() // at least one is NOT displayed
1275
1284
  * await expect(some($$('.items'))).toHaveText('foo')
1276
1285
  */
1277
- function some<T extends ElementArrayLike>(
1286
+ export function some<T extends ElementArrayLike>(
1278
1287
  elements: T
1279
1288
  ): WdioSome<T>
1280
1289
  }
1281
-
1282
- declare module 'expect-webdriverio' {
1283
- export = ExpectWebdriverIO
1284
- }