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

Flutter Widget Test doesn't seem to work. #57

Open
patterueldev opened this issue Jul 8, 2022 · 1 comment
Open

Flutter Widget Test doesn't seem to work. #57

patterueldev opened this issue Jul 8, 2022 · 1 comment

Comments

@patterueldev
Copy link

patterueldev commented Jul 8, 2022

I have two options when executing a tap:

/* by type: */ await tester.tap(find.byType(RoundedLoadingButton), warnIfMissed: true);
/* by key: */ await tester.tap(find.byKey(const Key("signInButton")), warnIfMissed: true);

But neither of them works at all. I get errors when trying to verify a certain function from a mock instance which is expected to be executed when the button is tapped.

This works with a regular TextButton by the way.

@patterueldev
Copy link
Author

I found the reason. This widget has its own test, and I analyzed the difference. It turns out the animateOnTap deems the test tap not work if enabled. For testing's sake, I turn it to false when testing:

RoundedLoadingButton(
  controller: _signInButtonController,
  child: const Text("SIGN IN"),
  onPressed: () => context
      .read<SignInBloc>()
      .add(SignInTapEvent(context)),
  animateOnTap: !Platform.environment
      .containsKey('FLUTTER_TEST'),
)

But it would be nice if we can still test it even if animateOnTap = true during tests.

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

1 participant