有没有办法在bunit测试中设置OnAfterRender方法的firstRender-Variable?
Is there a way to set the firstRender-Variable of the OnAfterRender method in bunit testing?
假设我有以下 class,我想同时测试 firstRender = false
和 firstRender=true
“路径”。为此,我正在使用 bunit 和 xunit。
public class ToTest {
protected async override void OnAfterRender(bool firstRender)
{
if(firstRender)
{
//do stuff
}
else
{
//do other stuff
}
}
}
public class TestClass : TestContext
{
[Fact]
public void Test()
{
//Arrange stuff before this method
var cut = RenderComponent<News>(parameters => parameters
.Add(p => p.authenticationStateTask, stateProvider.GetAuthenticationStateAsync()));
}
}
有没有办法在bunit测试中设置OnAfterRender方法的firstRender-Variable?
我必须调整渲染组件参数吗?
bUnit 允许您对被测组件执行多次渲染。第一个渲染将始终将 firstRender
设置为 true
,任何其他渲染都将其设置为 false
,就像常规 Blazor 运行时一样。
例如:
public class TestClass : TestContext
{
[Fact]
public void Test()
{
// First render, where firstRender is true
var cut = RenderComponent<News>(parameters => parameters
.Add(p => p.Param, "Bar"));
// Second render, where firstRender is false
cut.Render();
// Third render, with new parameters set during the render life-cycle
// and where firstRender is also false
cut.SetParametersAndRender(parameters => parameters
.Add(p => p.Param, "Foo"));
}
}
在此处了解更多信息:https://bunit.dev/docs/interaction/trigger-renders.html
假设我有以下 class,我想同时测试 firstRender = false
和 firstRender=true
“路径”。为此,我正在使用 bunit 和 xunit。
public class ToTest {
protected async override void OnAfterRender(bool firstRender)
{
if(firstRender)
{
//do stuff
}
else
{
//do other stuff
}
}
}
public class TestClass : TestContext
{
[Fact]
public void Test()
{
//Arrange stuff before this method
var cut = RenderComponent<News>(parameters => parameters
.Add(p => p.authenticationStateTask, stateProvider.GetAuthenticationStateAsync()));
}
}
有没有办法在bunit测试中设置OnAfterRender方法的firstRender-Variable? 我必须调整渲染组件参数吗?
bUnit 允许您对被测组件执行多次渲染。第一个渲染将始终将 firstRender
设置为 true
,任何其他渲染都将其设置为 false
,就像常规 Blazor 运行时一样。
例如:
public class TestClass : TestContext
{
[Fact]
public void Test()
{
// First render, where firstRender is true
var cut = RenderComponent<News>(parameters => parameters
.Add(p => p.Param, "Bar"));
// Second render, where firstRender is false
cut.Render();
// Third render, with new parameters set during the render life-cycle
// and where firstRender is also false
cut.SetParametersAndRender(parameters => parameters
.Add(p => p.Param, "Foo"));
}
}
在此处了解更多信息:https://bunit.dev/docs/interaction/trigger-renders.html