expectSnapshotFromSource function
void
expectSnapshotFromSource(})
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);
}