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 51 52 53 54 55 56 57 58 59 60 61
| import 'package:bloc_test/bloc_test.dart'; import 'package:equatable/equatable.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; import 'package:xdragon/services/interceptors/verify_permission.dart';
class CounterEvent extends Equatable { @override List<Object?> get props => []; }
class CounterIncrementEvent extends CounterEvent {}
class CounterDecrementEvent extends CounterEvent {}
class CounterState extends Equatable { final int count;
CounterState(this.count);
@override List<Object?> get props => [count]; }
class CounterBloc extends Bloc<CounterEvent, CounterState> { CounterBloc() : super(CounterState(0)) { on<CounterIncrementEvent>(onCounterIncrementEvent); on<CounterDecrementEvent>(onCounterDecrementEvent); }
void onCounterIncrementEvent(CounterEvent event, Emitter<CounterState> emit) { emit(CounterState(state.count + 1)); }
void onCounterDecrementEvent(CounterEvent event, Emitter<CounterState> emit) { emit(CounterState(state.count - 1)); } }
void main() { test('test event', () { expect(CounterEvent(), CounterEvent()); });
test('test state', () { expect(CounterState(10), CounterState(10)); });
blocTest<CounterBloc, CounterState>( 'CounterBloc test ', build: () => CounterBloc(), seed: () => CounterState(10), act: (bloc) => bloc.add(CounterIncrementEvent()), expect: () => [CounterState(11)], verify: (bloc) { expect(bloc.state.count , 11); }, ); }
|