diff --git a/src/index.ts b/src/index.ts index b79759e7..72b112f6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -32,23 +32,33 @@ type MatchersObject = Parameters[0] 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) -}) +const expectWithSoft = expectLib as unknown as ExpectWebdriverIO.Expect & SoftHelpers -// 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), -Object.defineProperty(expectWithSoft, 'clearSoftFailures', { - value: (testId?: string) => SoftAssertService.getInstance().clearFailures(testId) -}) + 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 }) + } +} export const expect = expectWithSoft