Skip to content

Commit

Permalink
fix: allow for checking non-existent elements (#1623)
Browse files Browse the repository at this point in the history
* fix: allow for checking non-existent elements

* fix: support non-existent elements in matchers
  • Loading branch information
goosewobbler authored and christian-bromann committed Aug 15, 2024
1 parent 7f9772d commit aba3962
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/matchers/element/toHaveAttribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function toHaveAttributeAndValue(received: ChainablePromiseElement,
const isNot = this.isNot
const { expectation = 'attribute', verb = 'have' } = this

let el = await received.getElement()
let el = await received?.getElement()
let attr
const pass = await waitUntil(async () => {
const result = await executeCommand.call(this, el, conditionAttrAndValue, options, [attribute, value, options])
Expand Down
2 changes: 1 addition & 1 deletion src/matchers/element/toHaveChildren.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function toHaveChildren(
? { eq: expectedValue } as ExpectWebdriverIO.NumberOptions
: expectedValue || {}

let el = await received.getElement()
let el = await received?.getElement()
let children
const pass = await waitUntil(async () => {
const result = await executeCommand.call(this, el, condition, numberOptions, [numberOptions])
Expand Down
2 changes: 1 addition & 1 deletion src/matchers/element/toHaveClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function toHaveElementClass(

const attribute = 'class'

let el = await received.getElement()
let el = await received?.getElement()
let attr

const pass = await waitUntil(async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/matchers/element/toHaveComputedLabel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function toHaveComputedLabel(
options,
})

let el = await received.getElement()
let el = await received?.getElement()
let actualLabel

const pass = await waitUntil(
Expand Down
2 changes: 1 addition & 1 deletion src/matchers/element/toHaveComputedRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function toHaveComputedRole(
options,
})

let el = await received.getElement()
let el = await received?.getElement()
let actualRole

const pass = await waitUntil(
Expand Down
2 changes: 1 addition & 1 deletion src/matchers/element/toHaveElementProperty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export async function toHaveElementProperty(
options,
})

let el = await received.getElement()
let el = await received?.getElement()
let prop: any
const pass = await waitUntil(
async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/matchers/element/toHaveHTML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ export async function toHaveHTML(
})

let el = 'getElement' in received
? await received.getElement()
? await received?.getElement()
: 'getElements' in received
? await received.getElements()
? await received?.getElements()
: received
let actualHTML

Expand Down
2 changes: 1 addition & 1 deletion src/matchers/element/toHaveHeight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function toHaveHeight(
options,
})

let el = await received.getElement()
let el = await received?.getElement()
let actualHeight

const pass = await waitUntil(
Expand Down
2 changes: 1 addition & 1 deletion src/matchers/element/toHaveSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function toHaveSize(
options,
})

let el = await received.getElement()
let el = await received?.getElement()
let actualSize

const pass = await waitUntil(
Expand Down
2 changes: 1 addition & 1 deletion src/matchers/element/toHaveStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function toHaveStyle(
options,
})

let el = await received.getElement()
let el = await received?.getElement()
let actualStyle

const pass = await waitUntil(async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/matchers/element/toHaveText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ export async function toHaveText(
})

let el = 'getElement' in received
? await received.getElement()
? await received?.getElement()
: 'getElements' in received
? await received.getElements()
? await received?.getElements()
: received
let actualText

Expand Down
2 changes: 1 addition & 1 deletion src/matchers/element/toHaveWidth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function toHaveWidth(
options,
})

let el = await received.getElement()
let el = await received?.getElement()
let actualWidth

const pass = await waitUntil(
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async function executeCommandBe(
): Promise<ExpectWebdriverIO.AssertionResult> {
const { isNot, expectation, verb = 'be' } = this

let el = await received.getElement()
let el = await received?.getElement()
const pass = await waitUntil(
async () => {
const result = await executeCommand.call(
Expand Down

0 comments on commit aba3962

Please sign in to comment.