Skip to content

Allow dynamic returns based on argumentsΒ #350

@alexandrevicenzi

Description

@alexandrevicenzi

C# Moq allows to return data based on call arguments.

testify/mock don't. It's possible to do using Run, but it's a big mess of code.

It would be great to have something like this:

myMock.On("Load", mock.AnythingOfType("string")).ReturnFn(func (token string) (*MyObj, error) {
    if isValid(token) {
        return someStuff(), nil
    } else {
        return nil, errors.New("Oh!")
    }
})

I can send a PR if someone like this idea.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions