generate static method
Generates a complete widget test file.
Implementation
static String generate({
required String widgetName,
required String importPath,
required bool isConst,
}) {
final constructor = isConst ? 'const $widgetName()' : '$widgetName()';
return '''
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import '$importPath';
void main() {
group('$widgetName', () {
testWidgets('renders correctly', (tester) async {
await tester.pumpWidget(
const MaterialApp(
home: $constructor,
),
);
expect(find.byType($widgetName), findsOneWidget);
});
testWidgets('matches golden snapshot', (tester) async {
await tester.pumpWidget(
const MaterialApp(
home: $constructor,
),
);
// TODO: Uncomment after generating golden file
// await expectLater(
// find.byType($widgetName),
// matchesGoldenFile('goldens/${_toSnakeCase(widgetName)}.png'),
// );
});
});
}
''';
}