Milad-Akarie / skeletonizer

MIT License
367 stars 24 forks source link

Can't find widget by type in widget tests. #24

Closed xVemu closed 9 months ago

xVemu commented 9 months ago

If you try to find widget by Skeletonizer type, it throws an error instead of passing findsOneWidget matcher.

Code sample ```dart void main() { testWidgets('skeleton', (driver) async { final widget = Skeletonizer(child: Text("test")); await driver.pumpWidget(MaterialApp(home: widget)); expect(find.byType(Skeletonizer, skipOffstage: false), findsOneWidget); }); } ```
Stacktrace ``` Testing started at 12:24 ... ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════ The following TestFailure was thrown running a test: Expected: exactly one matching candidate Actual: _TypeWidgetFinder: Which: means none were found but one was expected When the exception was thrown, this was the stack: #4 main. (file:///C:/Users/kkras/mobile/test/models/base/paging_result_model_test.dart:75:5) #5 testWidgets.. (package:flutter_test/src/widget_tester.dart:183:15) #6 TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:1017:5) (elided one frame from package:stack_trace) This was caught by the test expectation on the following line: file:///C:/Users/kkras/mobile/test/models/base/paging_result_model_test.dart line 75 The test description was: skeleton ════════════════════════════════════════════════════════════════════════════════════════════════════ Test failed. See exception logs above. The test description was: skeleton ```
xVemu commented 9 months ago

Just use SkeletonizerScope instead of Skeletonizer in byType.