From f49b186d0816192fb575c84951ef46aa5c987d0b Mon Sep 17 00:00:00 2001 From: goosewobbler <432005+goosewobbler@users.noreply.github.com> Date: Tue, 6 Aug 2024 02:38:02 +0100 Subject: [PATCH 1/2] fix: allow for checking non-existent elements --- src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.ts b/src/utils.ts index 6460daa6..a9488792 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -80,7 +80,7 @@ async function executeCommandBe( ): Promise { 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( From 17fa6b58078a08b5228c26ba09fb9c6963ac4b34 Mon Sep 17 00:00:00 2001 From: goosewobbler Date: Tue, 6 Aug 2024 13:09:27 +0100 Subject: [PATCH 2/2] fix: support non-existent elements in matchers --- src/matchers/element/toHaveAttribute.ts | 2 +- src/matchers/element/toHaveChildren.ts | 2 +- src/matchers/element/toHaveClass.ts | 2 +- src/matchers/element/toHaveComputedLabel.ts | 2 +- src/matchers/element/toHaveComputedRole.ts | 2 +- src/matchers/element/toHaveElementProperty.ts | 2 +- src/matchers/element/toHaveHTML.ts | 4 ++-- src/matchers/element/toHaveHeight.ts | 2 +- src/matchers/element/toHaveSize.ts | 2 +- src/matchers/element/toHaveStyle.ts | 2 +- src/matchers/element/toHaveText.ts | 4 ++-- src/matchers/element/toHaveWidth.ts | 2 +- 12 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/matchers/element/toHaveAttribute.ts b/src/matchers/element/toHaveAttribute.ts index 05e28f33..db7eae44 100644 --- a/src/matchers/element/toHaveAttribute.ts +++ b/src/matchers/element/toHaveAttribute.ts @@ -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]) diff --git a/src/matchers/element/toHaveChildren.ts b/src/matchers/element/toHaveChildren.ts index b1f9d17c..f9b03596 100644 --- a/src/matchers/element/toHaveChildren.ts +++ b/src/matchers/element/toHaveChildren.ts @@ -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]) diff --git a/src/matchers/element/toHaveClass.ts b/src/matchers/element/toHaveClass.ts index 9ee59b59..844363f3 100644 --- a/src/matchers/element/toHaveClass.ts +++ b/src/matchers/element/toHaveClass.ts @@ -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 () => { diff --git a/src/matchers/element/toHaveComputedLabel.ts b/src/matchers/element/toHaveComputedLabel.ts index 7d89ed2a..0e316d06 100644 --- a/src/matchers/element/toHaveComputedLabel.ts +++ b/src/matchers/element/toHaveComputedLabel.ts @@ -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( diff --git a/src/matchers/element/toHaveComputedRole.ts b/src/matchers/element/toHaveComputedRole.ts index aff5f010..22e139ee 100644 --- a/src/matchers/element/toHaveComputedRole.ts +++ b/src/matchers/element/toHaveComputedRole.ts @@ -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( diff --git a/src/matchers/element/toHaveElementProperty.ts b/src/matchers/element/toHaveElementProperty.ts index cbe0aba0..b4cde8c3 100644 --- a/src/matchers/element/toHaveElementProperty.ts +++ b/src/matchers/element/toHaveElementProperty.ts @@ -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 () => { diff --git a/src/matchers/element/toHaveHTML.ts b/src/matchers/element/toHaveHTML.ts index 2113a875..ac1e45e1 100644 --- a/src/matchers/element/toHaveHTML.ts +++ b/src/matchers/element/toHaveHTML.ts @@ -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 diff --git a/src/matchers/element/toHaveHeight.ts b/src/matchers/element/toHaveHeight.ts index 0f56fdd7..60d1c02a 100644 --- a/src/matchers/element/toHaveHeight.ts +++ b/src/matchers/element/toHaveHeight.ts @@ -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( diff --git a/src/matchers/element/toHaveSize.ts b/src/matchers/element/toHaveSize.ts index e447450b..e8bd5fd6 100644 --- a/src/matchers/element/toHaveSize.ts +++ b/src/matchers/element/toHaveSize.ts @@ -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( diff --git a/src/matchers/element/toHaveStyle.ts b/src/matchers/element/toHaveStyle.ts index a0890e3e..b0008e91 100644 --- a/src/matchers/element/toHaveStyle.ts +++ b/src/matchers/element/toHaveStyle.ts @@ -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 () => { diff --git a/src/matchers/element/toHaveText.ts b/src/matchers/element/toHaveText.ts index b7f637de..e03e20da 100644 --- a/src/matchers/element/toHaveText.ts +++ b/src/matchers/element/toHaveText.ts @@ -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 diff --git a/src/matchers/element/toHaveWidth.ts b/src/matchers/element/toHaveWidth.ts index df1ed102..80116bad 100644 --- a/src/matchers/element/toHaveWidth.ts +++ b/src/matchers/element/toHaveWidth.ts @@ -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(