Skip to content

Allow modifying HtmlComparers HtmlDiffer #1787

@md-at-slashwhy

Description

@md-at-slashwhy

Is the feature request related to a problem? Please elaborate.
When using bUnit to diff only element types a naive approach could be:

public void ExampleTest()
{
    const string expected = "<BlazorElement diff:ignoreAttributes></BlazorElement>";
    const string markup = """<DifferentBlazorElement some-attribute="value"></DifferentBlazorElement>""";

    var component = Render(markup.ToMarkupRenderFragment());

    component.MarkupMatches(expected);
}

However, this comparison does not fail and would cause the test to pass - which is unexpected.

The suggested solution
This could be fixed without changing existing behaviour by:
a) Allow changing the DiffingStrategyPipeline used in the HtmlComparer e.g. by providing a protected constructor and unsealing the class
b) Extract an interface for IHtmlComparer that can be injected into the DI

Describe any alternative solutions
The issue could be resolved by changing the existing behaviour to throw an exception which in turn would cause the test to fail. This would still not allow bUnit to be extended with further diffing strategy changes and might break existing tests.

Additional context
AngleSharp is highly extensible. The improved performance of sealing the class does not seem to be worth the lack of such extensibility in bUnit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions