expectSnapshotFromSource function

void expectSnapshotFromSource(
  1. Trellis engine,
  2. String source,
  3. Map<String, dynamic> context, {
  4. required String goldenFile,
  5. String? fragment,
})

Renders a template source string and compares against a golden file.

Same semantics as expectSnapshot but accepts a raw template source string instead of a template name. Useful when templates are defined inline in test code.

test('inline snapshot', () {
  expectSnapshotFromSource(
    engine,
    '<h1 tl:text="${title}">x</h1>',
    {'title': 'Hello'},
    goldenFile: 'test/goldens/inline.html',
  );
});

Implementation

void expectSnapshotFromSource(
  Trellis engine,
  String source,
  Map<String, dynamic> context, {
  required String goldenFile,
  String? fragment,
}) {
  final String rendered;
  if (fragment != null) {
    rendered = engine.renderFragment(source, fragment: fragment, context: context);
  } else {
    rendered = engine.render(source, context);
  }
  compareOrCreateGolden(normalizeHtml(rendered), goldenFile);
}