# flutter_svg_test

### Testing

This package provides a set of functions to find images generated by
[**flutter_svg**  ](https://github.com/dnfield/flutter_svg/tree/master/packages/flutter_svg)
in widget tests.

The methods find elements with the `SvgPicture` type and compare either the `BytesLoader` or the
configuration of the `BytesLoader` with the giving test attribute.

### Example

#### Find by BytesLoader

The following example shows how you can find svgs with the matching `SvgAssetLoader`.

<?code-excerpt "test/flutter_svg_test_test.dart (ByLoader)"?>
```dart
testWidgets('asset svg', (WidgetTester widgetTester) async {
  final asset = SvgPicture.asset('test/flutter_logo.svg');
  await widgetTester.pumpWidget(DefaultAssetBundle(bundle: _FakeAssetBundle(), child: asset));

  expect(find.svg(asset.bytesLoader), findsOneWidget);
});
```

#### Find by svg path

Sometimes it is more convenient instead of instantiating the whole `BytesLoader`
to compare only specific attributes.

The following example shows how you can find svgs with the specified attribute.

<?code-excerpt "test/flutter_svg_test_test.dart (ByPath)"?>
```dart
testWidgets('asset svg with path', (WidgetTester widgetTester) async {
  const svgPath = 'test/flutter_logo.svg';
  await widgetTester.pumpWidget(
    DefaultAssetBundle(bundle: _FakeAssetBundle(), child: SvgPicture.asset(svgPath)),
  );

  expect(find.svgAssetWithPath(svgPath), findsOneWidget);
});
```

## Commemoration

This package was originally authored by
[Dan Field](https://github.com/dnfield) and has been forked here
from [dnfield/flutter_svg](https://github.com/dnfield/flutter_svg).
Dan was a member of the Flutter team at Google from 2018 until his death
in 2024. Dan’s impact and contributions to Flutter were immeasurable, and we
honor his memory by continuing to publish and maintain this package.
