Verify positional parameter 'null' not working together with any()
- Dominant language
- Dart
- Stars
- 702
- Forks
- 88
- PR merge metrics
- No merged PRs in 30d
Description
**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
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.