mocktail
mocktail copied to clipboard
resetMocktailState is not resets state right
Describe the bug
resetMocktailState
docs says that it resets all mocktail states but doesn't.
It seems it does not reset verifying call count.
I found clearInteractions
and reset
seem to work perfectly as I intended.
/// Reset the state of Mocktail, typically for use between tests.
///
/// For example, when using the test package, mock methods may accumulate calls
/// in a `setUp` method, making it hard to verify method calls that were made
/// _during_ an individual test. Or, there may be unverified calls from previous
/// test cases that should not affect later test cases.
///
/// In these cases, [resetMocktailState] might be called at the end of `setUp`,
/// or in `tearDown`.
Did I miss something or is it intended?
To Reproduce Steps to reproduce the behavior:
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
class RealClass {
void func() {}
}
class MockClass extends Mock implements RealClass {}
void main() {
final mock = MockClass();
setUp(() {
when(mock.func).thenAnswer((_) => null);
});
tearDown(resetMocktailState);
test('Executed first', () {
mock
..func()
..func()
..func();
});
test('Executed last', () { ///
mock.func();
verify(mock.func).called(1);
/// This one fails
/// Expected: <1>
/// Actual: <4>
/// Unexpected number of calls
});
}
Expected behavior
resets clearly after invoking resetMocktailState
**Logs **
[√] Flutter (Channel stable, 2.10.2, on Microsoft Windows [Version 10.0.19043.1645], locale ko-KR)
• Flutter version 2.10.2 at C:\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 097d3313d8 (3 months ago), 2022-02-18 19:33:08 -0600
• Engine revision a83ed0e5e3
• Dart version 2.16.1
• DevTools version 2.9.2