expect-webdriverio 6.0.4 → 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.
@@ -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
  }
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.4",
3
+ "version": "6.0.5",
4
4
  "author": "Mykola Grybyk <mykola.grybyk@gmail.com>",
5
5
  "description": "WebdriverIO Assertion Library",
6
6
  "license": "MIT",