Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create widget test #24

Closed
samheyman opened this issue Apr 23, 2019 · 1 comment
Closed

Cannot create widget test #24

samheyman opened this issue Apr 23, 2019 · 1 comment

Comments

@samheyman
Copy link

samheyman commented Apr 23, 2019

I am trying to add a simple test to verify the login page shows when opened (as per the example test available on Flutter).

I get the following error, caused by the state_widget static _StateWidgetState data call:

static _StateWidgetState of (BuildContext context) {
    return (context.inheritFromWidgetOfExactType(_StateDataWidget)
            as _StateDataWidget)
        .data;
  }

This is the error message:

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following NoSuchMethodError was thrown building RootScreen(dirty, state:
_RootScreenState#941dc):
The getter 'data' was called on null.
Receiver: null
Tried calling: data

When the exception was thrown, this was the stack:
#0      Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:50:5)
#1      StateWidget.of (package:mama_fit_club/state_widget.dart:28:10)

This is the simple test:

void main() {
  testWidgets('Test login page displayed', (WidgetTester tester) async {
    // Build our app and trigger a frame.
    await tester.pumpWidget(StateWidget(child: MyApp()));
    final loginRequestFinder = find.text("To continue please login with");
    expect(loginRequestFinder, findsOneWidget);
  });
}

Are you able to help? I need to add tests to my app.

Thanks!

@krolmic
Copy link
Owner

krolmic commented Jun 2, 2019

Hi @samheyman,

what about the code of MyApp and RootScreen? Is it the same as in this repository?

If the problem is still present, you could send me a link to your repository, so we can figure out why the test is not running.

You can contact me on twitter "@krol_mic" or via mail michael.krol@pm.me.

Best regards
Michael

@krolmic krolmic closed this as completed Jun 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants