Skip to content

mock does not enforce arity if parameter is Anything #587

Description

@dnathe4th
package main_test

import (
	"testing"

	"github.com/stretchr/testify/mock"
)

type Foo interface {
	Bar()
}

type MockFoo struct {
	mock.Mock
}

// Bar provides a mock function with given fields:
func (_m *MockFoo) Bar() {
	_m.Called()
}

func TestFoo(t *testing.T) {
	foo := new(MockFoo)
	foo.On("Bar", mock.Anything).Return()

	foo.Bar() // expected error for unmocked call
}

The logic in Arguments.Diff does not check whether a given argument is required by the function signature before checking if the value is Anything. Phrased another way, there is no explicit arity check on the mocked method.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    mock.ArgumentMatcherAbout matching arguments in mockpkg-mockAny issues related to Mock

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions