testify icon indicating copy to clipboard operation
testify copied to clipboard

mock: add OnF method

Open burik666 opened this issue 2 months ago • 0 comments

Summary

Adds OnF method to mock.Mock and mock.Call to allow defining mock expectations using function references instead of string method names.

Changes

  • Added OnF method to mock.Mock and mock.Call.
  • OnF extracts the function name using reflection and runtime information.
  • Provides a more type-safe, refactor-friendly alternative to On.

Motivation

Currently, mock expectations are defined using string literals for method names, which can be error-prone and break easily during refactoring. OnF allows developers to use actual function references, improving type safety and maintainability.

Related issues

#425

burik666 avatar Oct 18 '25 14:10 burik666