Cannot distinguish 2 sequential action dispatch calls
- Dominant language
- Dart
- Stars
- 702
- Forks
- 88
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
When verifying that 2 actions have been dispatched from a redux store in a redux middleware one after the other, the verify function cannot distinguish the 2 actions, i.e. any of the 2 actions will match 2 calls instead of 1 each.
**To Reproduce**
`lib/middleware.dart`:
```
import 'package:equatable/equatable.dart';
import 'package:meta/meta.dart';
import 'package:redux/redux.dart';
List> getHomeMiddleware() => [
HomeMiddleware().getMiddlewareBindings(),
].expand((x) => x).toList();
class HomeMiddleware {
List> getMiddlewareBindings() => [
TypedMiddleware(_handleTriggerAction),
];
void _handleTriggerAction(Store store, TriggerAction action, next) {
next(action);
store.dispatch(DispatchedA());
store.dispatch(DispatchedB());
}
}
@immutable
class TriggerAction {
@override
String toString() {
return 'TriggerAction{}';
}
}
@immutable
class DispatchedA {
@override
String toString() {
return 'DispatchedA{}';
}
}
@immutable
class DispatchedB {
@override
String toString() {
return 'DispatchedB{}';
}
}
class AppState extends Equatable {
@override
List get props => [];
}
```
`test/middleware_test.dart`:
```
import 'package:flutter_test/flutter_test.dart';
import 'package:demo/middleware.dart';
import 'package:mocktail/mocktail.dart';
import 'package:redux/redux.dart';
void main() {
setUpAll(() {
registerFallbackValue(TriggerAction());
registerFallbackValue(DispatchedA());
registerFallbackValue(DispatchedB());
});
test('This is the test that fails', () async {
final store = StoreMock();
await getHomeMiddleware().call(store, TriggerAction());
verify(() => store.dispatch(any()));
verify(() => store.dispatch(any()));
});
}
class StoreMock extends Mock implements Store {}
extension MiddlewareExtension on List> {
Future call(Store store, dynamic action) async {
for (final middleware in this) {
await middleware.call(store, action, (_) {});
}
}
}
```
Steps to reproduce the behavior:
1. Run `flutter test`
2. See error
**Expected behavior**
Test passes.
**Logs**
```
package:test_api fail
package:mocktail/src/mocktail.dart 722:7 _VerifyCall._checkWith
package:mocktail/src/mocktail.dart 515:18 _makeVerify.
test/middleware_test.dart 19:11 main.
No matching calls. All calls: [VERIFIED] StoreMock.dispatch(DispatchedA{}), [VERIFIED] StoreMock.dispatch(DispatchedB{})
(If you called `verify(...).called(0);`, please instead use `verifyNever(...);`.)
```
**Additional context**
Tested on Mocktail versions 0.2.0 and 0.3.0.
Commenting out any of the 2 `verify` checks makes the test pass, so the checks both work on their own.
Adding `.called(2)` to any of the 2 `verify` checks and commenting out the other check makes the test pass, so it seems **there is no distinction between the 2 different actions**.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.