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

error running tests on latest packages #5

Open
cklanac opened this issue Aug 16, 2020 · 1 comment
Open

error running tests on latest packages #5

cklanac opened this issue Aug 16, 2020 · 1 comment

Comments

@cklanac
Copy link

cklanac commented Aug 16, 2020

Received the following error when running tests on the latest packages.

Test: "WHEN user enters a valid email and passwordAND user taps on the sign-in buttonTHEN
signInWithEmailAndPassword is calledAND user is signed in"

══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following assertion was thrown running a test:
Tried to listen to a value exposed with provider, from outside of the widget tree.

This is likely caused by an event handler (like a button's onPressed) that called
Provider.of without passing `listen: false`.

To fix, write:
Provider.of<AuthBase>(context, listen: false);

It is unsupported because may pointlessly rebuild the widget associated to the
event handler, when the widget tree doesn't care about the value.

The context used was: EmailSignInFormStateful(dirty, state: _EmailSignInFormStatefulState#4ce1f)
'package:provider/src/provider.dart':
Failed assertion: line 202 pos 7: 'context.owner.debugBuilding ||
          listen == false ||
          debugIsInInheritedProviderUpdate'

When the exception was thrown, this was the stack:
#2      Provider.of (package:provider/src/provider.dart:202:7)
#3      _EmailSignInFormStatefulState._submit (package:time_tracker_flutter_course/app/sign_in/email_sign_in_form_stateful.dart:46:29)
#4      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:992:19)
#5      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:1098:38)
#6      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:184:24)
#7      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:524:11)
#8      BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:284:5)
#9      BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:219:7)
#10     PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:477:9)
#11     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:78:12)
#12     PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:124:9)
#13     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:377:8)
#14     PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:122:18)
#15     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:108:7)
#16     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:220:19)
#17     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:200:22)
#18     TestWidgetsFlutterBinding.dispatchEvent (package:flutter_test/src/binding.dart:471:11)
#19     WidgetTester.sendEventToBinding.<anonymous closure> (package:flutter_test/src/widget_tester.dart:654:15)
#20     WidgetTester.sendEventToBinding.<anonymous closure> (package:flutter_test/src/widget_tester.dart:653:39)
#23     TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:72:41)
#24     WidgetTester.sendEventToBinding (package:flutter_test/src/widget_tester.dart:653:27)
#25     TestGesture.up.<anonymous closure> (package:flutter_test/src/test_pointer.dart:422:24)
#26     TestGesture.up.<anonymous closure> (package:flutter_test/src/test_pointer.dart:420:39)
#29     TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:72:41)
#30     TestGesture.up (package:flutter_test/src/test_pointer.dart:420:27)
#31     WidgetController.tapAt.<anonymous closure> (package:flutter_test/src/controller.dart:263:21)
#43     WidgetController.startGesture (package:flutter_test/src/controller.dart)
#54     FakeAsync.flushMicrotasks (package:fake_async/fake_async.dart:192:32)
#55     AutomatedTestWidgetsFlutterBinding.runTest.<anonymous closure> (package:flutter_test/src/binding.dart:1149:17)
#56     AutomatedTestWidgetsFlutterBinding.runTest.<anonymous closure> (package:flutter_test/src/binding.dart:1137:35)
(elided 42 frames from class _AssertionError, dart:async, dart:async-patch, and package:stack_trace)

The test description was:
  WHEN user enters a valid email and passwordAND user taps on the sign-in buttonTHEN
  signInWithEmailAndPassword is calledAND user is signed in
@cklanac
Copy link
Author

cklanac commented Aug 16, 2020

Fixed by adding listen: false to the _submit method. Fixed in PR #3

Future<void> _submit() async {
    setState(() {
      _submitted = true;
      _isLoading = true;
    });
    try {
      final auth = Provider.of<AuthBase>(context, listen: false);
      if (_formType == EmailSignInFormType.signIn) {
        await auth.signInWithEmailAndPassword(_email, _password);
      } else {
        await auth.createUserWithEmailAndPassword(_email, _password);
      }
      if (widget.onSignedIn != null) {
        widget.onSignedIn();
      }
    } on PlatformException catch (e) {
      PlatformExceptionAlertDialog(
        title: 'Sign in failed',
        exception: e,
      ).show(context);
    } finally {
      setState(() {
        _isLoading = false;
      });
    }
  }

@cklanac cklanac changed the title Error running tests on latest packages error running tests on latest packages Aug 16, 2020
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