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

Verify positional parameter 'null' not working together with any() #256

Open
moderateroni opened this issue Jan 13, 2025 · 0 comments
Open

Comments

@moderateroni
Copy link

moderateroni commented Jan 13, 2025

Describe the bug
When you have multiple positional parameters of the same (nullable) Type in your mocked Method, you cannot verify that one positional parameter is null and others are any().

To Reproduce
Steps to reproduce the behavior:

This Test will fail, but from my point of view it should not:

import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';

class MockListener extends Mock {
  void call(int? previous, int next);
}

void main() {
  late MockListener listener;

  setUp(() {
    listener = MockListener();
    registerFallbackValue(1);
  });

  test('verify listener is called with any()', () {
    // Arrange
    final previousInt = null;
    final nextInt = 3;

    // Act
    listener(previousInt, nextInt);

    // Assert
    verify(() => listener(null, any())).called(1);
  });
}

Expected behavior
Tests like this should not fail

Additional context
In _is_invocation.dart, there is this line of code in _reconstitutePositionalArgs:
if (positionalArgument == null || positionalArgument == arg._fallbackValue)

shouldn't the first check be removed? i did this and all tests are still successful.

easy workaround of course is to also use a matcher for the first positional argument, so
verify(() => listener(any(that: isNull), any())).called(1);
will work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant