Bunit.JSRuntimeUnhandledInvocationException : The invocation of 'blazorise.button.initialize' with arguments ... was not expected. #305
-
Describe the bug or question Example: @*
* FakeComponent.razor
* Note: It doesn't matter if I add parameter values, the end result is the same.
*@
@using Blazorise
<Button>A Button</Button> With this test (In an XUnit test project running .NET 5.0): <SnapshotTest Description="FakeComponent_SnapshotTest_ShouldRender" Setup="@SnapshotTestSetup">
<TestInput>
<FakeComponent />
</TestInput>
<ExpectedOutput>
<button type:ignore class:ignore style:ignore id:ignore>A Button</button>
</ExpectedOutput>
</SnapshotTest>
<Fixture Test="FakeComponent_FixtureTest_ShouldRender" Setup="@FixtureSetup">
<ComponentUnderTest>
<FakeComponent />
</ComponentUnderTest>
</Fixture>
@code
{
static void FixtureSetup(Fixture test)
{
test.Services
.AddBlazorise(options =>
{
options.ChangeTextOnKeyPress = true;
})
.AddBootstrapProviders()
.AddFontAwesomeIcons();
test.Services
.UseBootstrapProviders()
.UseFontAwesomeIcons();
}
static void SnapshotTestSetup(SnapshotTest test)
{
test.Services
.AddBlazorise(options =>
{
options.ChangeTextOnKeyPress = true;
})
.AddBootstrapProviders()
.AddFontAwesomeIcons();
test.Services
.UseBootstrapProviders()
.UseFontAwesomeIcons();
}
static void FakeComponent_FixtureTest_ShouldRender(Fixture test)
{
var cut = test.GetComponentUnderTest<FakeComponent>();
cut.MarkupMatches("<button type:ignore class:ignore style:ignore id:ignore>A Button</button>");
}
} Results in this output:
Whereas this test (In an MSTest project running .NET Core 3.1): using Bunit;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace EcoSystem.WebClientTest.Components
{
[TestClass]
public class FakeComponentTests : BunitTestContext
{
[TestMethod]
public void FakeComponent_CSharpTest_ShouldRender()
{
// This is using the BunitTestContext class specified here: https://bunit.egilhansen.com/docs/getting-started/writing-csharp-tests.html#remove-boilerplate-code-from-tests
var cut = RenderComponent<FakeComponent>();
cut.MarkupMatches("<button type:ignore class:ignore style:ignore id:ignore>Change Password</button>");
}
}
} Results in this output:
Expected behavior: Version info:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @jjones-ucpm Ill just give a quick answer before heading to bed, excuse the brevity on this one. The short answer is, that it is not a bug. Preview 1 has JSinterop enabled by default and set to strict mode. See https://github.com/egil/bUnit/releases/tag/v1.0.0-preview-01 for details. To fix it. try setting Ps. preview 01 is also compatible with netcoreapp3.1, so feel free to use the same version everywhere. |
Beta Was this translation helpful? Give feedback.
-
That did indeed do the trick! Thank you, @egil! |
Beta Was this translation helpful? Give feedback.
Hi @jjones-ucpm
Ill just give a quick answer before heading to bed, excuse the brevity on this one.
The short answer is, that it is not a bug. Preview 1 has JSinterop enabled by default and set to strict mode. See https://github.com/egil/bUnit/releases/tag/v1.0.0-preview-01 for details.
To fix it. try setting
test.JSInterop.Mode = JSRuntimeMode.Loose
in your setup methods.Ps. preview 01 is also compatible with netcoreapp3.1, so feel free to use the same version everywhere.