From 28cc190416f5c0a7a299edaa3828f332916748d8 Mon Sep 17 00:00:00 2001 From: JustasMonkev Date: Sun, 6 Jul 2025 12:15:20 +0300 Subject: [PATCH 1/3] =?UTF-8?q?fix(expect):=20guard=20property=20definitio?= =?UTF-8?q?ns=20to=20avoid=20=E2=80=9CCannot=20redefine=20property?= =?UTF-8?q?=E2=80=9D=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/index.ts b/src/index.ts index b79759e75..59dd891ec 100644 --- a/src/index.ts +++ b/src/index.ts @@ -33,22 +33,33 @@ expectLib.extend(filteredMatchers as MatchersObject) // Extend the expect object with soft assertions const expectWithSoft = expectLib as unknown as ExpectWebdriverIO.Expect -Object.defineProperty(expectWithSoft, 'soft', { - value: (actual: T) => createSoftExpect(actual) -}) -// Add soft assertions utility methods -Object.defineProperty(expectWithSoft, 'getSoftFailures', { - value: (testId?: string) => SoftAssertService.getInstance().getFailures(testId) -}) +type SoftHelpers = { + soft: (actual: T) => ReturnType + getSoftFailures: (testId?: string) => ReturnType + assertSoftFailures: (testId?: string) => void + clearSoftFailures: (testId?: string) => void +} -Object.defineProperty(expectWithSoft, 'assertSoftFailures', { - value: (testId?: string) => SoftAssertService.getInstance().assertNoFailures(testId) -}) +const helperFactories: SoftHelpers = { + soft: (actual: T) => createSoftExpect(actual), + + getSoftFailures: (testId?: string) => + SoftAssertService.getInstance().getFailures(testId), + + assertSoftFailures: (testId?: string) => + SoftAssertService.getInstance().assertNoFailures(testId), + + clearSoftFailures: (testId?: string) => + SoftAssertService.getInstance().clearFailures(testId) +} + +for (const [name, fn] of Object.entries(helperFactories)) { + if (!(name in expectWithSoft)) { + Object.defineProperty(expectWithSoft, name, { value: fn }) + } +} -Object.defineProperty(expectWithSoft, 'clearSoftFailures', { - value: (testId?: string) => SoftAssertService.getInstance().clearFailures(testId) -}) export const expect = expectWithSoft From d9afb285054d1a43604e51578b5bc32b4b86d185 Mon Sep 17 00:00:00 2001 From: JustasMonkev Date: Sun, 6 Jul 2025 12:15:25 +0300 Subject: [PATCH 2/3] =?UTF-8?q?fix(expect):=20guard=20property=20definitio?= =?UTF-8?q?ns=20to=20avoid=20=E2=80=9CCannot=20redefine=20property?= =?UTF-8?q?=E2=80=9D=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 59dd891ec..b3134f223 100644 --- a/src/index.ts +++ b/src/index.ts @@ -60,7 +60,6 @@ for (const [name, fn] of Object.entries(helperFactories)) { } } - export const expect = expectWithSoft export const getConfig = (): ExpectWebdriverIO.DefaultOptions => DEFAULT_OPTIONS From fb52975dfca1196734df0c77e9f8c7d5e832e905 Mon Sep 17 00:00:00 2001 From: JustasMonkev Date: Sun, 6 Jul 2025 12:22:34 +0300 Subject: [PATCH 3/3] fix(expect): extend expect with soft assertion helpers --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index b3134f223..72b112f6b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -32,7 +32,7 @@ type MatchersObject = Parameters[0] expectLib.extend(filteredMatchers as MatchersObject) // Extend the expect object with soft assertions -const expectWithSoft = expectLib as unknown as ExpectWebdriverIO.Expect +const expectWithSoft = expectLib as unknown as ExpectWebdriverIO.Expect & SoftHelpers type SoftHelpers = { soft: (actual: T) => ReturnType