UNPKG

expect-webdriverio

Version:

WebdriverIO Assertion Library

39 lines (38 loc) 1.33 kB
import { DEFAULT_OPTIONS } from '../../constants.js'; import { enhanceError, executeCommand, waitUntil, wrapExpectedWithArray } from '../../utils.js'; async function condition(el, width) { const actualWidth = await el.getSize('width'); return { value: actualWidth, result: actualWidth === width, }; } export async function toHaveWidth(received, expectedValue, options = DEFAULT_OPTIONS) { const isNot = this.isNot; const { expectation = 'width', verb = 'have' } = this; await options.beforeAssertion?.({ matcherName: 'toHaveWidth', expectedValue, options, }); let el = await received?.getElement(); let actualWidth; const pass = await waitUntil(async () => { const result = await executeCommand.call(this, el, condition, options, [expectedValue, options]); el = result.el; actualWidth = result.values; return result.success; }, isNot, options); const message = enhanceError(el, wrapExpectedWithArray(el, actualWidth, expectedValue), actualWidth, this, verb, expectation, '', options); const result = { pass, message: () => message }; await options.afterAssertion?.({ matcherName: 'toHaveWidth', expectedValue, options, result }); return result; }