Skip to content

Instantly share code, notes, and snippets.

@techpotatoes
Created June 2, 2020 14:43
Show Gist options
  • Save techpotatoes/742bc662808bf0da0a2c6a7e20f44dc1 to your computer and use it in GitHub Desktop.
Save techpotatoes/742bc662808bf0da0a2c6a7e20f44dc1 to your computer and use it in GitHub Desktop.
Flutter development series – Part 5
// ignore_for_file: invalid_override_different_default_values_named, must_be_immutable
class MockNavigatorKey extends Mock implements GlobalKey<NavigatorState> {}
class MockCurrentState extends Mock implements NavigatorState {
@override
String toString({DiagnosticLevel minLevel = DiagnosticLevel.debug}) =>
super.toString();
}
void main() {
group('Given a Navigator BLoC', () {
final mockNavigatorKey = MockNavigatorKey();
final mockCurrentState = MockCurrentState();
when(mockNavigatorKey.currentState).thenReturn(mockCurrentState);
test('should pop navigator when NavigatorActionPop', () {
final navigatorBloc = NavigatorBloc(navigatorKey: mockNavigatorKey);
navigatorBloc.add(NavigatorEventPop());
expectLater(navigatorBloc, emitsInOrder(["Initial", "Updated"]))
.then((value) => verify(mockCurrentState.pop()));
});
test('should push named when NavigatorActionAdd', () {
final navigatorBloc = NavigatorBloc(navigatorKey: mockNavigatorKey);
navigatorBloc.add(NavigatorEventAdd());
expectLater(navigatorBloc, emitsInOrder(["Initial", "Updated"]))
.then((value) => verify(mockCurrentState.pushNamed('/add')));
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment