toMatchImageSnapshot method Null safety

Future<void> toMatchImageSnapshot(
  1. String id,
  2. {List<RegExp>? removeExps}
)

Implementation

Future<void> toMatchImageSnapshot(String id,
    {List<RegExp>? removeExps}) async {
  final currentSnapshot =
      await Snapshot.getSnapshotFromFile(id, SnapshotType.image, options);
  final newSnapshot = await Snapshot.getSnapshotFromDriver(
      id, SnapshotType.image, driver, removeExps);

  if (newSnapshot == null) {
    throw Exception(
        'SnapshotTest: (toMatchRenderTreeSnapshot) New Snapshot is null');
  }

  if (currentSnapshot == null || options.forceCaptureMode) {
    await newSnapshot.save(options);
    return;
  }

  try {
    currentSnapshot.matchesSnapshot(newSnapshot);
    return;
  } on TestFailure catch (_) {
    await saveFailure(currentSnapshot, newSnapshot);
    rethrow;
  } catch (_) {
    rethrow;
  }
}