testGoldens function

  1. @isTest
void testGoldens(
  1. String description,
  2. Future<void> test(
    1. WidgetTester
    ), {
  3. bool? skip,
  4. Object? tags = _defaultTagObject,
})

This testGoldens method exists as a way to enforce the proper naming of tests that contain golden diffs so that we can reliably run all goldens

description is a test description

skip to skip the test

test test body

Implementation

@isTest
void testGoldens(
  String description,
  Future<void> Function(WidgetTester) test, {
  bool? skip,
  Object? tags = _defaultTagObject,
}) {
  final dynamic config = Zone.current[#goldentoolkit.config];
  testWidgets(
    description,
    (tester) async {
      Future<void> body() async {
        _inGoldenTest = true;
        final initialDebugDisableShadowsValue = debugDisableShadows;
        final shouldUseRealShadows =
            GoldenToolkit.configuration.enableRealShadows;
        debugDisableShadows = !shouldUseRealShadows;
        try {
          await test(tester);
        } finally {
          debugDisableShadows = initialDebugDisableShadowsValue;
          _inGoldenTest = false;
        }
      }

      if (config is GoldenToolkitConfiguration) {
        await GoldenToolkit.runWithConfiguration(body, config: config);
      } else {
        await body();
      }
    },
    skip: skip,
    tags: tags != _defaultTagObject ? tags : GoldenToolkit.configuration.tags,
  );
}