state_notifier_test 0.0.7 state_notifier_test: ^0.0.7 copied to clipboard
A testing library which makes it easy to test StateNotifier. Built to be used with the state_notifier, riverpod or flutter_riverpod packages.
import 'package:state_notifier/state_notifier.dart';
import 'package:mockito/mockito.dart';
import 'package:state_notifier_test/state_notifier_test.dart';
import 'package:test/test.dart';
// Mock StateNotifier
class MockCounterStateNotifier extends Mock implements CounterStateNotifier {}
void main() {
group('CounterStateNotifier', () {
stateNotifierTest<CounterStateNotifier, int>(
'emits [] when nothing is added',
actions: (_) {},
build: () => CounterStateNotifier(),
expect: () => const <int>[],
);
stateNotifierTest<CounterStateNotifier, int>(
'emits [1] when increment is called',
build: () => CounterStateNotifier(),
actions: (CounterStateNotifier notifier) => notifier.increment(),
expect: () => const <int>[1],
);
});
}
class CounterStateNotifier extends StateNotifier<int> {
CounterStateNotifier() : super(0);
void increment() {
state = state + 1;
}
}