Skip to content

Commit 4f15022

Browse files
linkdotnetegil
authored andcommitted
fix: bUnit can handle relative units in Markup
1 parent 70cb5c1 commit 4f15022

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ All notable changes to **bUnit** will be documented in this file. The project ad
99
### Fixed
1010

1111
- 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)
12+
- Use default renderer properties for AngleSharp. Reported by [@jtleaming](https://github.com/jtleaming) in [#1692].
1213

1314
## [1.38.5] - 2025-01-12
1415

src/bunit.web/Rendering/BunitHtmlParser.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections;
22
using System.Diagnostics;
33
using AngleSharp;
4+
using AngleSharp.Css;
45
using AngleSharp.Dom;
56
using AngleSharp.Html.Parser;
67
using Bunit.Diffing;
@@ -28,7 +29,8 @@ public sealed class BunitHtmlParser : IDisposable
2829
/// with a AngleSharp context without a <see cref="TestRenderer"/> registered.
2930
/// </summary>
3031
public BunitHtmlParser()
31-
: this(Configuration.Default.WithCss().With(new HtmlComparer())) { }
32+
: this(Configuration.Default.WithCss()
33+
.With(new HtmlComparer())) { }
3234

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

4446
private BunitHtmlParser(IConfiguration angleSharpConfiguration)
4547
{
46-
var config = angleSharpConfiguration.With(this);
48+
var config = angleSharpConfiguration
49+
.With(this)
50+
.WithRenderDevice(new DefaultRenderDevice
51+
{
52+
ViewPortWidth = 1920,
53+
ViewPortHeight = 1080,
54+
});
4755
context = BrowsingContext.New(config);
4856
var parseOptions = new HtmlParserOptions
4957
{
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<div class="my-component" style="width: 5%">
2+
</div>

tests/bunit.web.tests/Rendering/RenderedComponentTest.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using AngleSharp;
2+
using AngleSharp.Css;
3+
using AngleSharp.Dom;
14
using Bunit.Rendering;
25

36
namespace Bunit;
@@ -67,4 +70,14 @@ public void Test021()
6770
cut.Instance.JSRuntime.ShouldNotBeNull();
6871
}
6972
#endif
73+
74+
[Fact(DisplayName = "Using relative units in style attribute can be retrieved")]
75+
public void Test022()
76+
{
77+
var cut = RenderComponent<ComponentWithRelativeUnitAsWidth>();
78+
79+
var text = cut.Find(".my-component").GetInnerText();
80+
81+
text.ShouldNotBeNull();
82+
}
7083
}

0 commit comments

Comments
 (0)