Skip to content

Adding structs for Throwing Mock References#22

Open
sebastianozane wants to merge 2 commits into
danielsaidi:masterfrom
sebastianozane:feature/adding-throwing-mock-references
Open

Adding structs for Throwing Mock References#22
sebastianozane wants to merge 2 commits into
danielsaidi:masterfrom
sebastianozane:feature/adding-throwing-mock-references

Conversation

@sebastianozane
Copy link
Copy Markdown

@sebastianozane sebastianozane commented May 26, 2026

This adds support for mocking functions that throw errors through two new reference types: ThrowingMockReference & AsyncThrowingMockReference.

While the current library supports mocking references that throw errors, the try? in the current implementation of call swallows errors thrown by the registered result and results in an erroneous precondition failure: "You must register a result for '\(functionCall)' with registerResult(for:) before calling this function.".

An alternative would have been to change the existing call APIs to propagate errors. That would have been a breaking change, since existing mock implementations would need to add try/throws handling when calling their mock references.

To guide users toward the new API, this also adds deprecation warnings when throwing functions or throwing result closures are used with the non-throwing reference types.

@sebastianozane sebastianozane marked this pull request as ready for review May 26, 2026 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant