-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.dart
50 lines (43 loc) · 1.63 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import 'package:mockito/mockito.dart';
import 'package:state_notifier/state_notifier.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]);
stateNotifierTest<CounterStateNotifier, int>(
'emits [0,1] when increment is called with expectInitialState set to true',
expectInitialState: true,
build: () => CounterStateNotifier(),
actions: (CounterStateNotifier notifier) => notifier.increment(),
expect: () => const <int>[0, 1],
);
stateNotifierTest<CounterStateNotifier, int>(
'tests matchers for expected result',
expectInitialState: true,
build: () => CounterStateNotifier(),
actions: (CounterStateNotifier notifier) => notifier.increment(),
expect: () => isA<List>().having((list) => list.length, 'contains 2 elements', 2),
);
},
);
}
class CounterStateNotifier extends StateNotifier<int> {
CounterStateNotifier() : super(0);
void increment() {
state = state + 1;
}
}