Skip to content

Never returning async stubbing #556

@jdanthinne

Description

@jdanthinne

I'm testing a timeout case in my test, and my stubbed service has this method func myMethod() async throws -> String.

When stubbing this method, I can use theReturn or thenThrow, but how to make my method never return?

I'm cheating in the following code by sleeping longer than the defined timeout then returning a value, but is there a cleaner way?

stub(mock) { stub in
    when(stub.myMethod()).then { _ in
        sleep(5)
        return ""
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions