Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/matchers/browser/toHaveClipboardText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export async function toHaveClipboardText(
expectedValue: string | RegExp | WdioAsymmetricMatcher<string>,
options: ExpectWebdriverIO.StringOptions = DEFAULT_OPTIONS
) {
const isNot = this.isNot
const { expectation = 'clipboard text', verb = 'have' } = this

await options.beforeAssertion?.({
Expand All @@ -28,7 +27,7 @@ export async function toHaveClipboardText(
.catch((err) => log.warn(`Couldn't set clipboard permissions: ${err}`))
actual = await browser.execute(() => window.navigator.clipboard.readText())
return compareText(actual, expectedValue, options).result
}, isNot, options)
}, options)

const message = enhanceError('browser', expectedValue, actual, this, verb, expectation, '', options)
const result: ExpectWebdriverIO.AssertionResult = {
Expand Down
3 changes: 1 addition & 2 deletions src/matchers/browser/toHaveTitle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export async function toHaveTitle(
expectedValue: string | RegExp | WdioAsymmetricMatcher<string>,
options: ExpectWebdriverIO.StringOptions = DEFAULT_OPTIONS
) {
const isNot = this.isNot
const { expectation = 'title', verb = 'have' } = this

await options.beforeAssertion?.({
Expand All @@ -20,7 +19,7 @@ export async function toHaveTitle(
actual = await browser.getTitle()

return compareText(actual, expectedValue, options).result
}, isNot, options)
}, options)

const message = enhanceError('window', expectedValue, actual, this, verb, expectation, '', options)
const result: ExpectWebdriverIO.AssertionResult = {
Expand Down
3 changes: 1 addition & 2 deletions src/matchers/browser/toHaveUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export async function toHaveUrl(
expectedValue: string | RegExp | WdioAsymmetricMatcher<string>,
options: ExpectWebdriverIO.StringOptions = DEFAULT_OPTIONS
) {
const isNot = this.isNot
const { expectation = 'url', verb = 'have' } = this

await options.beforeAssertion?.({
Expand All @@ -20,7 +19,7 @@ export async function toHaveUrl(
actual = await browser.getUrl()

return compareText(actual, expectedValue, options).result
}, isNot, options)
}, options)

const message = enhanceError('window', expectedValue, actual, this, verb, expectation, '', options)
const result: ExpectWebdriverIO.AssertionResult = {
Expand Down
14 changes: 6 additions & 8 deletions src/matchers/element/toHaveAttribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ async function conditionAttrAndValue(el: WebdriverIO.Element, attribute: string,
}

export async function toHaveAttributeAndValue(received: WdioElementMaybePromise, attribute: string, value: string | RegExp | WdioAsymmetricMatcher<string>, options: ExpectWebdriverIO.StringOptions = DEFAULT_OPTIONS) {
const isNot = this.isNot
const { expectation = 'attribute', verb = 'have' } = this

let el = await received?.getElement()
Expand All @@ -38,7 +37,7 @@ export async function toHaveAttributeAndValue(received: WdioElementMaybePromise,
attr = result.values

return result.success
}, isNot, options)
}, options)

const expected = wrapExpectedWithArray(el, attr, value)
const message = enhanceError(el, expected, attr, this, verb, expectation, attribute, options)
Expand All @@ -49,9 +48,8 @@ export async function toHaveAttributeAndValue(received: WdioElementMaybePromise,
} as ExpectWebdriverIO.AssertionResult
}

async function toHaveAttributeFn(received: WdioElementMaybePromise, attribute: string) {
const isNot = this.isNot
const { expectation = 'attribute', verb = 'have' } = this
async function toHaveAttributeFn(received: WdioElementMaybePromise, attribute: string, options: ExpectWebdriverIO.StringOptions) {
const { expectation = 'attribute', verb = 'have', isNot } = this

let el = await received?.getElement()

Expand All @@ -60,9 +58,9 @@ async function toHaveAttributeFn(received: WdioElementMaybePromise, attribute: s
el = result.el as WebdriverIO.Element

return result.success
}, isNot, {})
}, options)

const message = enhanceError(el, !isNot, pass, this, verb, expectation, attribute, {})
const message = enhanceError(el, !isNot, pass, this, verb, expectation, attribute, options)

return {
pass,
Expand All @@ -86,7 +84,7 @@ export async function toHaveAttribute(
// Name and value is passed in e.g. el.toHaveAttribute('attr', 'value', (opts))
? await toHaveAttributeAndValue.call(this, received, attribute, value, options)
// Only name is passed in e.g. el.toHaveAttribute('attr')
: await toHaveAttributeFn.call(this, received, attribute)
: await toHaveAttributeFn.call(this, received, attribute, options)

await options.afterAssertion?.({
matcherName: 'toHaveAttribute',
Expand Down
3 changes: 1 addition & 2 deletions src/matchers/element/toHaveChildren.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export async function toHaveChildren(
expectedValue?: number | ExpectWebdriverIO.NumberOptions,
options: ExpectWebdriverIO.StringOptions = DEFAULT_OPTIONS
) {
const isNot = this.isNot
const { expectation = 'children', verb = 'have' } = this

await options.beforeAssertion?.({
Expand All @@ -56,7 +55,7 @@ export async function toHaveChildren(
children = result.values

return result.success
}, isNot, { ...numberOptions, ...options })
}, { ...numberOptions, ...options })

const error = numberError(numberOptions)
const expectedArray = wrapExpectedWithArray(el, children, error)
Expand Down
3 changes: 1 addition & 2 deletions src/matchers/element/toHaveClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export async function toHaveElementClass(
expectedValue: string | RegExp | Array<string | RegExp> | WdioAsymmetricMatcher<string>,
options: ExpectWebdriverIO.StringOptions = DEFAULT_OPTIONS
) {
const isNot = this.isNot
const { expectation = 'class', verb = 'have' } = this

await options.beforeAssertion?.({
Expand All @@ -62,7 +61,7 @@ export async function toHaveElementClass(
attr = result.values

return result.success
}, isNot, options)
}, options)

const message = enhanceError(el, wrapExpectedWithArray(el, attr, expectedValue), attr, this, verb, expectation, '', options)
const result: ExpectWebdriverIO.AssertionResult = {
Expand Down
2 changes: 0 additions & 2 deletions src/matchers/element/toHaveComputedLabel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export async function toHaveComputedLabel(
expectedValue: string | RegExp | WdioAsymmetricMatcher<string> | Array<string | RegExp>,
options: ExpectWebdriverIO.StringOptions = DEFAULT_OPTIONS
) {
const isNot = this.isNot
const { expectation = 'computed label', verb = 'have' } = this

await options.beforeAssertion?.({
Expand All @@ -46,7 +45,6 @@ export async function toHaveComputedLabel(

return result.success
},
isNot,
options
)

Expand Down
2 changes: 0 additions & 2 deletions src/matchers/element/toHaveComputedRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export async function toHaveComputedRole(
expectedValue: string | RegExp | WdioAsymmetricMatcher<string> | Array<string | RegExp>,
options: ExpectWebdriverIO.StringOptions = DEFAULT_OPTIONS
) {
const isNot = this.isNot
const { expectation = 'computed role', verb = 'have' } = this

await options.beforeAssertion?.({
Expand All @@ -46,7 +45,6 @@ export async function toHaveComputedRole(

return result.success
},
isNot,
options
)

Expand Down
9 changes: 5 additions & 4 deletions src/matchers/element/toHaveElementProperty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ async function condition(
const { asString = false } = options

let prop = await el.getProperty(property)

// As specified in the w3c spec, cases where property does not exist
if (prop === null || prop === undefined) {
return { result: false, value: prop }
}

// As specified in the w3c spec, cases where property simply exists, missing undefined here?
if (value === null) {
return { result: true, value: prop }
}
Expand All @@ -36,11 +39,10 @@ async function condition(
export async function toHaveElementProperty(
received: WdioElementMaybePromise,
property: string,
value?: string | RegExp | WdioAsymmetricMatcher<string>,
value?: string | RegExp | WdioAsymmetricMatcher<string> | null,
options: ExpectWebdriverIO.StringOptions = DEFAULT_OPTIONS
) {
const isNot = this.isNot
const { expectation = 'property', verb = 'have' } = this
const { expectation = 'property', verb = 'have', isNot } = this

await options.beforeAssertion?.({
matcherName: 'toHaveElementProperty',
Expand All @@ -58,7 +60,6 @@ export async function toHaveElementProperty(

return result.success
},
isNot,
options
)

Expand Down
3 changes: 1 addition & 2 deletions src/matchers/element/toHaveHTML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export async function toHaveHTML(
expectedValue: string | RegExp | WdioAsymmetricMatcher<string> | Array<string | RegExp>,
options: ExpectWebdriverIO.HTMLOptions = DEFAULT_OPTIONS
) {
const isNot = this.isNot
const { expectation = 'HTML', verb = 'have' } = this

await options.beforeAssertion?.({
Expand All @@ -44,7 +43,7 @@ export async function toHaveHTML(
actualHTML = result.values

return result.success
}, isNot, options)
}, options)

const message = enhanceError(el, wrapExpectedWithArray(el, actualHTML, expectedValue), actualHTML, this, verb, expectation, '', options)

Expand Down
2 changes: 0 additions & 2 deletions src/matchers/element/toHaveHeight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export async function toHaveHeight(
expectedValue: number | ExpectWebdriverIO.NumberOptions,
options: ExpectWebdriverIO.CommandOptions = DEFAULT_OPTIONS
) {
const isNot = this.isNot
const { expectation = 'height', verb = 'have' } = this

await options.beforeAssertion?.({
Expand Down Expand Up @@ -53,7 +52,6 @@ export async function toHaveHeight(

return result.success
},
isNot,
{ ...numberOptions, ...options }
)

Expand Down
2 changes: 0 additions & 2 deletions src/matchers/element/toHaveSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export async function toHaveSize(
expectedValue: { height: number; width: number },
options: ExpectWebdriverIO.CommandOptions = DEFAULT_OPTIONS
) {
const isNot = this.isNot
const { expectation = 'size', verb = 'have' } = this

await options.beforeAssertion?.({
Expand All @@ -40,7 +39,6 @@ export async function toHaveSize(

return result.success
},
isNot,
options
)

Expand Down
3 changes: 1 addition & 2 deletions src/matchers/element/toHaveStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export async function toHaveStyle(
expectedValue: { [key: string]: string; },
options: ExpectWebdriverIO.StringOptions = DEFAULT_OPTIONS
) {
const isNot = this.isNot
const { expectation = 'style', verb = 'have' } = this

await options.beforeAssertion?.({
Expand All @@ -35,7 +34,7 @@ export async function toHaveStyle(
actualStyle = result.values

return result.success
}, isNot, options)
}, options)

const message = enhanceError(el, wrapExpectedWithArray(el, actualStyle, expectedValue), actualStyle, this, verb, expectation, '', options)

Expand Down
3 changes: 1 addition & 2 deletions src/matchers/element/toHaveText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export async function toHaveText(
expectedValue: string | RegExp | WdioAsymmetricMatcher<string> | Array<string | RegExp>,
options: ExpectWebdriverIO.StringOptions = DEFAULT_OPTIONS
) {
const isNot = this.isNot
const { expectation = 'text', verb = 'have' } = this

await options.beforeAssertion?.({
Expand All @@ -64,7 +63,7 @@ export async function toHaveText(
actualText = result.values

return result.success
}, isNot, options)
}, options)

const message = enhanceError(el, wrapExpectedWithArray(el, actualText, expectedValue), actualText, this, verb, expectation, '', options)
const result: ExpectWebdriverIO.AssertionResult = {
Expand Down
2 changes: 0 additions & 2 deletions src/matchers/element/toHaveWidth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export async function toHaveWidth(
expectedValue: number | ExpectWebdriverIO.NumberOptions,
options: ExpectWebdriverIO.CommandOptions = DEFAULT_OPTIONS
) {
const isNot = this.isNot
const { expectation = 'width', verb = 'have' } = this

await options.beforeAssertion?.({
Expand Down Expand Up @@ -53,7 +52,6 @@ export async function toHaveWidth(

return result.success
},
isNot,
{ ...numberOptions, ...options }
)

Expand Down
3 changes: 1 addition & 2 deletions src/matchers/elements/toBeElementsArrayOfSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export async function toBeElementsArrayOfSize(
expectedValue: number | ExpectWebdriverIO.NumberOptions,
options: ExpectWebdriverIO.StringOptions = DEFAULT_OPTIONS
) {
const isNot = this.isNot
const { expectation = 'elements array of size', verb = 'be' } = this

await options.beforeAssertion?.({
Expand Down Expand Up @@ -38,7 +37,7 @@ export async function toBeElementsArrayOfSize(
}
elements = await refetchElements(elements, numberOptions.wait, true)
return false
}, isNot, { ...numberOptions, ...options })
}, { ...numberOptions, ...options })

if (Array.isArray(received) && pass) {
for (let index = originalLength; index < elements.length; index++) {
Expand Down
3 changes: 1 addition & 2 deletions src/matchers/mock/toBeRequestedTimes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export async function toBeRequestedTimes(
expectedValue: number | ExpectWebdriverIO.NumberOptions = {},
options: ExpectWebdriverIO.StringOptions = DEFAULT_OPTIONS
) {
const isNot = this.isNot || false
const { expectation = `called${typeof expectedValue === 'number' ? ' ' + expectedValue : '' } time${expectedValue !== 1 ? 's' : ''}`, verb = 'be' } = this

await options.beforeAssertion?.({
Expand All @@ -25,7 +24,7 @@ export async function toBeRequestedTimes(
const pass = await waitUntil(async () => {
actual = received.calls.length
return compareNumbers(actual, numberOptions)
}, isNot, { ...numberOptions, ...options })
}, { ...numberOptions, ...options })

const error = numberError(numberOptions)
const message = enhanceError('mock', error, actual, this, verb, expectation, '', numberOptions)
Expand Down
4 changes: 1 addition & 3 deletions src/matchers/mock/toBeRequestedWith.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ export async function toBeRequestedWith(
expectedValue: ExpectWebdriverIO.RequestedWith = {},
options: ExpectWebdriverIO.CommandOptions = DEFAULT_OPTIONS
) {
const isNot = this.isNot || false
const { expectation = 'called with', verb = 'be' } = this
const { expectation = 'called with', verb = 'be', isNot } = this

await options.beforeAssertion?.({
matcherName: 'toBeRequestedWith',
Expand Down Expand Up @@ -54,7 +53,6 @@ export async function toBeRequestedWith(

return false
},
isNot,
{ ...options, wait: isNot ? 0 : options.wait }
)

Expand Down
Loading