testNotifier<SN extends StateNotifier<State> , State> function
Internal stateNotifierTest runner which is only visible for testing. This should never be used directly -- please use stateNotifierTest instead.
Implementation
@visibleForTesting
Future<void> testNotifier<SN extends StateNotifier<State>, State>({
required FutureOr Function(SN stateNotifier) actions,
dynamic Function()? expect,
required SN Function() build,
Iterable<State> Function()? seed,
FutureOr<void> Function(SN stateNotifier)? verify,
FutureOr<void> Function()? tearDown,
dynamic Function()? errors,
FutureOr<void> Function()? setUp,
required int skip,
bool expectInitialState = false,
}) async {
final unhandledErrors = <Object>[];
await setUp?.call();
List<State> states = <State>[];
final stateNotifier = build();
stateNotifier.addListener(
(state) {
states.add(state);
},
fireImmediately: expectInitialState,
);
if (seed != null) {
final seedStates = seed.call();
for (var state in seedStates) {
// ignore: invalid_use_of_protected_member
stateNotifier.state = state;
}
}
try {
await actions.call(stateNotifier);
} catch (error) {
if (errors == null) rethrow;
unhandledErrors.add(error);
}
stateNotifier.dispose();
states = states.skip(skip).toList();
final expected = expect?.call();
try {
if (expect != null) {
test.expect(states, test.wrapMatcher(expected));
}
// ignore: nullable_type_in_catch_clause
} on test.TestFailure catch (e) {
final diff = _diff(expected: expected, actual: states);
final message = '${e.message}\n$diff';
// ignore: only_throw_errors
throw test.TestFailure(message);
}
await verify?.call(stateNotifier);
await tearDown?.call();
}