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 failing when using get_it #171

Closed
jikeyt opened this issue Apr 9, 2021 · 1 comment
Closed

Flutter widget test failing when using get_it #171

jikeyt opened this issue Apr 9, 2021 · 1 comment

Comments

@jikeyt
Copy link

jikeyt commented Apr 9, 2021

The tests in the example project of get_it is failing. PFB the logs. Similar issue is happening in my actual project

`══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following assertion was thrown building Builder:
Object/factory with type AppModel is not registered inside GetIt.
(Did you accidentally do GetIt sl=GetIt.instance(); instead of GetIt sl=GetIt.instance;
Did you forget to register it?)
'package:get_it/get_it_impl.dart':
Failed assertion: line 316 pos 7: 'instanceFactory != null'

The relevant error-causing widget was:
MaterialApp file:///Users/gaurabkumar/Downloads/get_it-master/example/lib/main.dart:19:12

When the exception was thrown, this was the stack:
#2 _GetItImplementation._findFactoryByNameAndType (package:get_it/get_it_impl.dart:316:7)
#3 _GetItImplementation.isReady (package:get_it/get_it_impl.dart:1094:24)
#4 _MyHomePageState.initState (package:get_it_example/main.dart:44:10)
#5 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4806:58)
#6 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4643:5)
... Normal element mounting (132 frames)
#138 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3612:14)
#139 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6330:32)
... Normal element mounting (273 frames)
#412 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3612:14)
#413 Element.updateChild (package:flutter/src/widgets/framework.dart:3359:20)
#414 RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1252:16)
#415 RenderObjectToWidgetElement.update (package:flutter/src/widgets/binding.dart:1230:5)
#416 RenderObjectToWidgetElement.performRebuild (package:flutter/src/widgets/binding.dart:1244:7)
#417 Element.rebuild (package:flutter/src/widgets/framework.dart:4381:5)
#418 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2733:33)
#419 AutomatedTestWidgetsFlutterBinding.drawFrame (package:flutter_test/src/binding.dart:1088:18)
#420 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:302:5)
#421 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1117:15)
#422 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1055:9)
#423 AutomatedTestWidgetsFlutterBinding.pump. (package:flutter_test/src/binding.dart:961:9)
#426 TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:72:41)
#427 AutomatedTestWidgetsFlutterBinding.pump (package:flutter_test/src/binding.dart:948:27)
#428 WidgetTester.pumpWidget. (package:flutter_test/src/widget_tester.dart:524:22)
#431 TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:72:41)
#432 WidgetTester.pumpWidget (package:flutter_test/src/widget_tester.dart:521:27)
#433 main. (file:///Users/gaurabkumar/Downloads/get_it-master/example/test/widget_test.dart:16:18)
#434 main. (file:///Users/gaurabkumar/Downloads/get_it-master/example/test/widget_test.dart:14:48)
#435 testWidgets.. (package:flutter_test/src/widget_tester.dart:146:29)
#446 FakeAsync.flushMicrotasks (package:fake_async/fake_async.dart:193:32)
#447 AutomatedTestWidgetsFlutterBinding.runTest. (package:flutter_test/src/binding.dart:1189:17)
#448 AutomatedTestWidgetsFlutterBinding.runTest. (package:flutter_test/src/binding.dart:1177:35)
(elided 31 frames from class _AssertionError, dart:async, and package:stack_trace)

═══════════════════════════════════════════════════════════════════════════════════════════════════
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following TestFailure object was thrown running a test:
Expected: exactly one matching node in the widget tree
Actual: _TextFinder:<zero widgets with text "0" (ignoring offstage widgets)>
Which: means none were found but one was expected

When the exception was thrown, this was the stack:
#4 main. (file:///Users/gaurabkumar/Downloads/get_it-master/example/test/widget_test.dart:19:5)

#5 main. (file:///Users/gaurabkumar/Downloads/get_it-master/example/test/widget_test.dart)
#6 testWidgets.. (package:flutter_test/src/widget_tester.dart:146:29)

#7 testWidgets.. (package:flutter_test/src/widget_tester.dart)
#8 TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:784:19)

#11 TestWidgetsFlutterBinding._runTest (package:flutter_test/src/binding.dart:764:14)
#12 AutomatedTestWidgetsFlutterBinding.runTest. (package:flutter_test/src/binding.dart:1173:24)
#13 FakeAsync.run.. (package:fake_async/fake_async.dart:178:54)
#18 withClock (package:clock/src/default.dart:48:10)
#19 FakeAsync.run. (package:fake_async/fake_async.dart:178:22)
#24 FakeAsync.run (package:fake_async/fake_async.dart:178:7)
#25 AutomatedTestWidgetsFlutterBinding.runTest (package:flutter_test/src/binding.dart:1170:15)
#26 testWidgets. (package:flutter_test/src/widget_tester.dart:138:24)
#27 Declarer.test.. (package:test_api/src/backend/declarer.dart:175:19)

#28 Declarer.test.. (package:test_api/src/backend/declarer.dart)
#33 Declarer.test. (package:test_api/src/backend/declarer.dart:173:13)
#34 Invoker.waitForOutstandingCallbacks. (package:test_api/src/backend/invoker.dart:231:15)
#39 Invoker.waitForOutstandingCallbacks (package:test_api/src/backend/invoker.dart:228:5)
#40 Invoker._onRun... (package:test_api/src/backend/invoker.dart:383:17)

#41 Invoker._onRun... (package:test_api/src/backend/invoker.dart)
#46 Invoker._onRun.. (package:test_api/src/backend/invoker.dart:370:9)
#47 Invoker._guardIfGuarded (package:test_api/src/backend/invoker.dart:415:15)
#48 Invoker._onRun. (package:test_api/src/backend/invoker.dart:369:7)
#55 Invoker._onRun (package:test_api/src/backend/invoker.dart:368:11)
#56 LiveTestController.run (package:test_api/src/backend/live_test_controller.dart:153:11)
#57 RemoteListener._runLiveTest. (package:test_api/src/remote_listener.dart:256:16)
#62 RemoteListener._runLiveTest (package:test_api/src/remote_listener.dart:255:5)
#63 RemoteListener._serializeTest. (package:test_api/src/remote_listener.dart:208:7)
#81 _GuaranteeSink.add (package:stream_channel/src/guarantee_channel.dart:125:12)
#82 new _MultiChannel. (package:stream_channel/src/multi_channel.dart:159:31)
#86 CastStreamSubscription._onData (dart:_internal/async_cast.dart:85:11)
#120 new _WebSocketImpl._fromSocket. (dart:_http/websocket_impl.dart:1145:21)
#128 _WebSocketProtocolTransformer._messageFrameEnd (dart:_http/websocket_impl.dart:338:23)
#129 _WebSocketProtocolTransformer.add (dart:_http/websocket_impl.dart:232:46)
#139 _Socket._onData (dart:io-patch/socket_patch.dart:2044:41)
#148 new _RawSocket. (dart:io-patch/socket_patch.dart:1580:33)
#149 _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1076:14)
(elided 111 frames from dart:async and package:stack_trace)

This was caught by the test expectation on the following line:
file:///Users/gaurabkumar/Downloads/get_it-master/example/test/widget_test.dart line 19
The test description was:
Counter increments smoke test
════════════════════════════════════════════════════════════════════════════════════════════════════
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following message was thrown:
Multiple exceptions (2) were detected during the running of the current test, and at least one was
unexpected.
════════════════════════════════════════════════════════════════════════════════════════════════════
Test failed. See exception logs above.
The test description was: Counter increments smoke test

✖ Counter increments smoke test
Exited (1)

`

@escamoteur
Copy link
Collaborator

Oh you're right, indeed this test file can't work in the way it is at the moment and honestly it wasn't maintained in any way so I deleted it now. The reason why it couldn't work is that at the beginning of the test nothing was reduced to insert get it.
If you get an similar error it's probably because you haven't registered all your types before you use them to tell you more about this I would need more information.

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