Skip to content

Rebase v2 on main #1694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: v2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -6,9 +6,13 @@ All notable changes to **bUnit** will be documented in this file. The project ad

## [Unreleased]

## [1.39.5] - 2025-04-04

### Fixed

- Do not set the `Uri` or `BaseUri` property on the `FakeNavigationManager` if navigation is prevented by a handler on `net7.0` or greater. Reported and fixed by [@ayyron-dev](https://github.com/ayyron-dev) in [#1647](https://github.com/bUnit-dev/bUnit/issues/1647)
- Use default renderer properties for AngleSharp. Reported by [@jtleaming](https://github.com/jtleaming) in [#1692].
- `FindComponents` throws an exception, when a base and derived class was searched for. Reported by [@BlueDragon709](https://github.com/BlueDragon709) in [#1691].

## [1.38.5] - 2025-01-12

@@ -1439,7 +1443,8 @@ The latest version of the library is availble on NuGet:
- **Wrong casing on keyboard event dispatch helpers.**
The helper methods for the keyboard events was not probably cased, so that has been updated. E.g. from `Keypress(...)` to `KeyPress(...)`.

[unreleased]: https://github.com/bUnit-dev/bUnit/compare/v1.38.5...HEAD
[unreleased]: https://github.com/bUnit-dev/bUnit/compare/v1.39.5...HEAD
[1.39.5]: https://github.com/bUnit-dev/bUnit/compare/v1.38.5...1.39.5
[1.38.5]: https://github.com/bUnit-dev/bUnit/compare/v1.37.7...v1.38.5
[1.37.7]: https://github.com/bUnit-dev/bUnit/compare/v1.36.0...1.37.7
[1.36.0]: https://github.com/bUnit-dev/bUnit/compare/v1.35.3...v1.36.0
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ A huge thank you to the [sponsors of bUnit](https://github.com/sponsors/egil). T
<table border="0">
<tr>
<td align="center" width="120">
<a href="https://github.com/syncfusion">
<a href="https://www.syncfusion.com/blazor-components?utm_source=bunit&utm_medium=cpc&utm_campaign=bunit_blazor_bancy25">
<img class="avatar" src="https://avatars.githubusercontent.com/u/1699795?s=460" width="72" height="72" alt="@syncfusion" />
<br />
Syncfusion
2 changes: 1 addition & 1 deletion docs/site/docs/verification/semantic-html-comparison.md
Original file line number Diff line number Diff line change
@@ -105,7 +105,7 @@ Here are the customization options you have available to you:
```html
<header>
<h1 id="head-1" diff:ignoreCase>HeLLo <em>world</em></h1>
</header
</header>
```

To perform case insensitive comparison of the text inside the `id` attribute, do the following:
7 changes: 6 additions & 1 deletion docs/site/index.md
Original file line number Diff line number Diff line change
@@ -53,11 +53,16 @@ bUnit is available on NuGet in various incarnations. Most users should just pick
A huge thank you to the [sponsors of bUnit](https://github.com/sponsors/egil). The higher tier sponsors are:

<div class="d-flex flex-row mb-3">
<a href="https://github.com/syncfusion" class="d-block p-3 text-center">
<a href="https://www.syncfusion.com/blazor-components?utm_source=bunit&utm_medium=cpc&utm_campaign=bunit_blazor_bancy25" class="d-block p-3 text-center">
<img class="avatar avatar rounded-circle" src="https://avatars.githubusercontent.com/u/1699795?s=460" width="72" height="72" alt="@syncfusion" />
<br />
Syncfusion
</a>
<a href="https://github.com/JetBrainsOfficial" class="d-block p-3 text-center">
<img class="avatar avatar rounded-circle" src="https://avatars.githubusercontent.com/u/60931315?v=4" width="72" height="72" alt="@JetBrainsOfficial" />
<br />
JetBrains
</a>
</div>

## Contributors
8 changes: 7 additions & 1 deletion src/bunit.core/Rendering/TestRenderer.cs
Original file line number Diff line number Diff line change
@@ -610,7 +610,13 @@ private IRenderedComponentBase<TComponent> GetOrCreateRenderedComponent<TCompone
{
if (renderedComponents.TryGetValue(componentId, out var renderedComponent))
{
return (IRenderedComponentBase<TComponent>)renderedComponent;
if (renderedComponent is IRenderedComponentBase<TComponent> typedComponent)
{
return typedComponent;
}

renderedComponent.Dispose();
renderedComponents.Remove(componentId);
}

LoadRenderTreeFrames(componentId, framesCollection);
12 changes: 10 additions & 2 deletions src/bunit.web/Rendering/BunitHtmlParser.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections;
using System.Diagnostics;
using AngleSharp;
using AngleSharp.Css;
using AngleSharp.Dom;
using AngleSharp.Html.Parser;
using Bunit.Diffing;
@@ -28,7 +29,8 @@ public sealed class BunitHtmlParser : IDisposable
/// with a AngleSharp context without a <see cref="TestRenderer"/> registered.
/// </summary>
public BunitHtmlParser()
: this(Configuration.Default.WithCss().With(new HtmlComparer())) { }
: this(Configuration.Default.WithCss()
.With(new HtmlComparer())) { }

/// <summary>
/// Initializes a new instance of the <see cref="BunitHtmlParser"/> class
@@ -43,7 +45,13 @@ public BunitHtmlParser(HtmlComparer htmlComparer, TestContextBase testContext)

private BunitHtmlParser(IConfiguration angleSharpConfiguration)
{
var config = angleSharpConfiguration.With(this);
var config = angleSharpConfiguration
.With(this)
.WithRenderDevice(new DefaultRenderDevice
{
ViewPortWidth = 1920,
ViewPortHeight = 1080,
});
context = BrowsingContext.New(config);
var parseOptions = new HtmlParserOptions
{
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<div class="my-component" style="width: 5%">
</div>
43 changes: 43 additions & 0 deletions tests/bunit.web.tests/Rendering/RenderedComponentTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using AngleSharp;
using AngleSharp.Css;
using AngleSharp.Dom;
using Bunit.Rendering;

namespace Bunit;
@@ -66,5 +69,45 @@ public void Test021()

cut.Instance.JSRuntime.ShouldNotBeNull();
}

[Fact(DisplayName = "Searching first for derived component and then base component finds correct (#1691)")]
public void Test023()
{
var cut = RenderComponent<Wrapper>(
ps => ps.AddChildContent<BaseComponent>()
.AddChildContent<DerivedComponent>());

Should.NotThrow(() =>
{
cut.FindComponents<BaseComponent>();
cut.FindComponents<DerivedComponent>();
});
}

private class BaseComponent : ComponentBase
{
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.AddContent(0, "base");
}
}

private sealed class DerivedComponent : BaseComponent
{
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.AddContent(0, "derived");
}
}
#endif

[Fact(DisplayName = "Using relative units in style attribute can be retrieved")]
public void Test022()
{
var cut = RenderComponent<ComponentWithRelativeUnitAsWidth>();

var text = cut.Find(".my-component").GetInnerText();

text.ShouldNotBeNull();
}
}
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json",
"version": "1.39-preview",
"version": "1.40-preview",
"assemblyVersion": {
"precision": "revision"
},