expectGolden<T> method
- @isTest
- WindowConfigData windowConfig, {
- String? suffix,
- Key? byKey,
- bool waitForImages = true,
Visual regression test for a given WindowConfigData.
Implementation
@isTest
Future<void> expectGolden<T>(
WindowConfigData windowConfig, {
String? suffix,
Key?
byKey, // Sometimes we want to find the widget by its unique key in the case they are multiple of the same type.
bool waitForImages = true,
}) async {
final enforcedTestPlatform =
AdaptiveTestConfiguration.instance.enforcedTestPlatform;
if (enforcedTestPlatform != null &&
!enforcedTestPlatform.isRuntimePlatform) {
throw ('Runtime platform ${Platform.operatingSystem} is not ${enforcedTestPlatform.name}');
}
final localSuffix = suffix != null ? "_${ReCase(suffix).snakeCase}" : '';
final name = ReCase('$T');
if (waitForImages) {
await awaitImages();
}
await expectLater(
// Find by its type except if the widget's unique key was given.
byKey != null ? find.byKey(byKey) : find.byType(AdaptiveWrapper),
matchesGoldenFile(
'preview/${windowConfig.name}:${name.snakeCase}$localSuffix.png',
),
);
}