mirror of
https://github.com/stretchr/testify.git
synced 2025-05-31 11:42:44 +00:00
We cannot compare two Func arguments to check if they are equal using the reflect package. This leads to the following misleading panic: ```go handler := func(http.ResponseWriter, *http.Request) {} muxMock.On("HandleFunc", "/", handler) muxMock.HandleFunc("/", handler) // panics arguing handler != handler ``` Since we cannot fix this behaviour using reflection, this patch provides a better panic with a meaningful workaround. ```go handler := func(http.ResponseWriter, *http.Request) {} muxMock.On("HandleFunc", "/", handler) // panics recommending defining the expectatin with: // AnythingOfType("func(http.ResponseWriter, *http.Request)") ``` Solution following the panic's instructions: ```go handler := func(http.ResponseWriter, *http.Request) {} muxMock.On("HandleFunc", "/", mock.AnythingOfType("func(http.ResponseWriter, *http.Request)")) muxMock.HandleFunc("/", handler) ```