monarch icon indicating copy to clipboard operation
monarch copied to clipboard

Create golden tests?

Open HugoHeneault opened this issue 3 years ago • 1 comments

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!

HugoHeneault avatar Jan 17 '22 08:01 HugoHeneault

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(...);
});

fertrig avatar Jan 18 '22 21:01 fertrig