How do I run Flutter widget tests with shadows enabled?

Viewed 351
1 Answers

With the debugDisableShadows flag.

import 'package:flutter_test/flutter_test.dart';

void main() {
  testWidgets('my golden test with shadows enabled', (tester) async {
    // Enable shadows
    debugDisableShadows = false;

    await tester.pumpWidget(MyWidget());
    await expectLater(find.byType(MyWidget), matchesGoldenFile('..'));

    // Set the flag back to normal
    debugDisableShadows = true;
  });
}

Note that you have to toggle the flag back to normal inside the test case (and not setUp / tearDown) - otherwise, it will fail.

This happens because this check is performed immediately after the body of testWidgets() completes, but before the test case is considered finished. Which is also before tearDown() is executed.

Related