bytedance/mockey

Please document conditional mock

17hao opened this issue · 1 comments

17hao commented

How to use conditional mock in mockey?

Mock(Foo).When().Return().Build()

please refer to mock_test.go, if you want to mock Fun only if the input argument equals a:

func Fun(a string) string {
    return a
}

you can do this:

Mock(Fun).When(func(a string) bool { return a == "a" }).Return("c").Build()

fmt.Println(Fun("a")) // "c", mocked
fmt.Println(Fun("b")) // "b", not mocked

We will improve relevant documentation in the future.