Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verifyNoMoreInteractions shouldn't error out on Mock of Function #277

Open
hopeman15 opened this issue Sep 10, 2020 · 1 comment
Open

verifyNoMoreInteractions shouldn't error out on Mock of Function #277

hopeman15 opened this issue Sep 10, 2020 · 1 comment
Labels
P3 A lower priority bug or feature request

Comments

@hopeman15
Copy link

First off, thanks for dart mockito 🙏

I've been using mockito for a while and haven't run into any issues until now. I have the following test checking if the function of my flutter widget was called, which works as expected. However while calling verifyNoMoreInteractions(testFunction); I always get the following error:

Invalid argument(s): verifyNoMoreInteractions must only be given a Mock object

As far as I can see the method is mocked, even the verify(testFunction.call(50)).called(2); works correctly. Any tips and or help would be greatly appreciated 👍

class MockFunction extends Mock implements Function {
  void call(double param);
}

void main() {
  void Function(double) testFunction;

  setUp(() {
    testFunction = MockFunction();
    when(testFunction.call(any)).thenAnswer((_) {});
  });

  tearDown(() {
    verifyNoMoreInteractions(testFunction);
  });

  testWidgets('test default slider', (WidgetTester tester) async {
    const value = 15;

    await tester.pumpWidget(
      MaterialApp(
        home: MyCustomSlider(
          onChanged: testFunction,
          value: value,
        ),
      ),
    );

    // test function was called
    await tester.drag(find.byType(Slider), Offset(0.0, 0.0));
    await tester.pumpAndSettle();

    // onChange called twice, by tap and slide
    verify(testFunction.call(50)).called(2);
  });
}

Thanks for your time and keep up the good work 🚀

@srawlins
Copy link
Member

srawlins commented Mar 9, 2021

Generally, Mockito is not designed to work on top-level functions. I'd be surprised if anything really works in the Mockito API given a class MockFunction extends Mock implements Function.

@srawlins srawlins changed the title verifyNoMoreInteractions shouldn't error out on Mock object verifyNoMoreInteractions shouldn't error out on Mock of Function May 26, 2021
@srawlins srawlins added the P3 A lower priority bug or feature request label May 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 A lower priority bug or feature request
Projects
None yet
Development

No branches or pull requests

2 participants