-
-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathRenderedComponentTest.cs
More file actions
83 lines (63 loc) · 2.49 KB
/
RenderedComponentTest.cs
File metadata and controls
83 lines (63 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using AngleSharp;
using AngleSharp.Css;
using AngleSharp.Dom;
using Bunit.Rendering;
namespace Bunit;
public class RenderedComponentTest : TestContext
{
[Fact(DisplayName = "Call to Render() results in a render of component")]
public void Test001()
{
var cut = RenderComponent<Wrapper>(parameters => parameters.AddChildContent("<div>"));
var initialRenderCount = cut.RenderCount;
cut.Render();
cut.RenderCount.ShouldBe(initialRenderCount + 1);
}
[Fact(DisplayName = "Call to SetParametersAndRender(builder) provides the parameters to component")]
public void Test004()
{
var cut = RenderComponent<Wrapper>(parameters => parameters.AddChildContent("<div>"));
cut.SetParametersAndRender(parameters => parameters.AddChildContent("<p>"));
cut.Find("p").ShouldNotBeNull();
}
[Fact(DisplayName = "Call to SetParametersAndRender(params) provides the parameters to component")]
public void Test0041()
{
var cut = RenderComponent<Wrapper>(parameters => parameters.AddChildContent("<div>"));
cut.SetParametersAndRender(ComponentParameterFactory.ChildContent("<p>"));
cut.Find("p").ShouldNotBeNull();
}
[Fact(DisplayName = "Trying to set CascadingValue during SetParametersAndRender throws")]
public void Test003()
{
// arrange
var cut = RenderComponent<AllTypesOfParams<string>>();
// assert
Should.Throw<InvalidOperationException>(() => cut.SetParametersAndRender(ps => ps.Add(p => p.UnnamedCascadingValue, 42)));
Should.Throw<InvalidOperationException>(() => cut.SetParametersAndRender(ps => ps.Add(p => p.NamedCascadingValue, 1337)));
}
[Fact(DisplayName = "Getting Instance from a RenderedComponent based on a disposed component throws")]
public void Test020()
{
var cut = RenderComponent<ToggleChildComponent>(ps => ps.Add(p => p.ShowChild, true));
var target = cut.FindComponent<Simple1>();
// Disposes of <Simple1 />
cut.SetParametersAndRender(ps => ps.Add(p => p.ShowChild, false));
Should.Throw<ComponentDisposedException>(() => target.Instance);
}
#if NET9_0_OR_GREATER
[Fact(DisplayName = "Component with constructor dependencies is resolved when rendered")]
public void Test021()
{
var cut = RenderComponent<ConstructorInjectionComponent>();
cut.Instance.JSRuntime.ShouldNotBeNull();
}
#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();
}
}