1

I tried to write the first smoke test for my Flutter app:

class MockStore extends Mock implements Store<AppState> {}

void main() {
  MockStore mockStore;
  setUp(() {
    mockStore = MockStore();
    when(mockStore.state).thenReturn(AppState.initial());
  });

  testWidgets('Login screen smoke test', (WidgetTester tester) async {
    // Build our app and trigger a frame.
    await tester.pumpWidget(App(mockStore,));

    // Verify that title is shown.
    expect(find.text('Sign in with google'), findsOneWidget);
  });
}

But I'm getting:

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following NoSuchMethodError was thrown building StoreConnector<AppState, _ViewModel>:
The method 'map' was called on null.
Receiver: null
Tried calling: map<_ViewModel>(Closure: (AppState) => _ViewModel)

How to properly mock the Store?

Dawid Hyży
  • 3,581
  • 5
  • 26
  • 41

1 Answers1

0

Your mock needs to return something for the onChange getter, eg:

when(mockStore.onChange).thenAnswer((_) =>
    Stream.fromIterable([AppState.intial()]));
Nick
  • 1,166
  • 11
  • 12