Replies: 1 comment 2 replies
-
Hey @MLHN01 , the reason you are seeing the issue is that your test-razor file is inheriting from the "default" @using System
@using System.Collections.Generic
@using Bunit
@using UnitTestGrid.Components
@inherits Bunit.TestContext
@attribute [TestClass]
@code{
[TestMethod]
public void TestMethod1()
{
var isClicked = false;
var cut = Render<TestComponent>(
@<TestComponent
@bind-IsClicked="@isClicked">
</TestComponent>
);
cut.Find("#TheButton").Click();
Assert.IsTrue(isClicked);
} That will work. As a note to us (@egil), we should consider removing all of those |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I have encountered an error that I can not explain.
I created a minimal example of my problem.
There is a TestComponent.razor which invokes a EventCallback on a button click. Its defined like this:
I want to test it by simulate the click with bUnit like this:
As you can see in "TestMethod1" i try to render the component directly and bind the "IsClicked" attribute from my test class. On run I get the this exception: "System.InvalidOperationException: The render handle is not yet assigned." for "TestMethod1".
In "TestMethod2" i wrapped my component in a simple Razor file like this:
In this case i dont get this exception at all and the test runs perfectly. In my project use case it would be much cleaner to test my component like in "TestMethod1". Have i missed something ? Whats the difference of these two cases?
I would appreciate any explanation for this.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions