How to make mockery detect typos in foo.On("MyMethox")? #765
-
In my setup v2.35.3 mockery does not complain, if I have a type like Or if I don't provide an argument to a method which requires an argument. If the method of the interface requires a string, and I just use foo.On("MethodWhichWantsAString"), then this gets silently ignored. This can waste precious time. Is there a way to make mockery complain typos and missing arguments? about that? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes, usage of the It's not 100% fool proof because the argument types in the method are |
Beta Was this translation helpful? Give feedback.
Yes, usage of the
.EXPECT()
builder pattern. This returns a struct with methods that are (mostly) identical to your interface. So one of its methods would be, in your example,.MethodWhichWantsAString("foobar")
. This will automatically call out the appropriate expectation in testify. This method is a bit more type safe as if you can't misspell the method name, and if you miss an argument, you'll get compiler errors.It's not 100% fool proof because the argument types in the method are
interface{}
because we need a way to specifymock.Anything
. A way to get around that is something likemock.EXPECT().MethodWhichWantsAString(mock.Anything).RunAndReturn(func(s string){ return "foo" })
. This …