Dropsource / monarch

Monarch is a tool for building Flutter widgets in isolation. It makes it easy to build, test and debug complex UIs.
https://monarchapp.io
MIT License
452 stars 25 forks source link

Create golden tests? #34

Open HugoHeneault opened 2 years ago

HugoHeneault commented 2 years ago

Hi there!

Monarch looks awesome. I haven't seen anything about creating images of stories, then testing they don't change later. I'm using https://pub.dev/packages/golden_toolkit which is great to avoid unwanted design changes/regressions.

It would be awesome to create goldens from monarch then test it: great design, then great tests!

Thanks for your cool work here!

fertrig commented 2 years ago

Love the feedback!

Visual testing is definitely on our roadmap. We can't wait to start working on it. We think Monarch can drastically improve the golden test experience.

For now, if you are using golden_toolkit, then you can call your stories from your golden tests. Something like this should work:

// my_stories.dart
Widget primaryButton() => ...;
Widget secondaryButton() => ...;
// my_golden_tests.dart
testGoldens('my buttons', (tester) async {
  await tester.pumpWidgetBuilder(
    Center(
        child: (GoldenBuilder.column()
              ..addScenario('primary button',
                  primaryButton())
              ..addScenario('secondary button',
                  secondaryButton())
            .build()),
    surfaceSize: ...,
  );
  await screenMatchesGolden(...);
});