-
-
Notifications
You must be signed in to change notification settings - Fork 118
Version 2.6.2 JSInterop does not implement IJSRuntime's InvokeConstructorAsync #1818
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
When using the current version of BUnit to test a component containing JSInteropt using the InvokConstructorAsync methods. Then I will get a NotImplementedException.
Example:
Component.razor.cs;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
// ...
var jsFileUri = $"./_content/{nameof(Component)}.razor.js";
this.javascriptModule ??= await this
.JsInterop
.InvokeAsync<IJSObjectReference>("import", jsFileUri);
this.javascriptResizerInstance = await this
.javascriptModule
.InvokeConstructorAsync("JsClass", this.ContainerElement, this.HandleElement);
}Component.razor.js;
export class FlyoutResizer {
container;
handle;
constructor(container, handle) {
this.container = container;
this.handle = handle;
this.handle.addEventListener('mousedown', e => this.onMouseDown(e));
}
onMouseDown(e) {
// ....
}
//...
}With this test:
[Fact]
public void WhenOpenRendersFlyoutPanel()
{
using var ctx = new BunitContext();
var cut = ctx.Render<Component>());
cut.Find(".flyout-panel").OuterHtml.Should().NotBeEmpty();
}Results in this output:
System.NotImplementedException
The method or operation is not implemented.
at Microsoft.JSInterop.IJSObjectReference.InvokeConstructorAsync(String identifier, Object[] args)
at Microsoft.JSInterop.JSObjectReferenceExtensions.InvokeConstructorAsync(IJSObjectReference jsObjectReference, String identifier, Object[] args)
at Component.OnAfterRenderAsync(Boolean firstRender) in C:\Projects\Component.razor.cs:line 59
at Bunit.Rendering.BunitRenderer.AssertNoUnhandledExceptions() in /_/src/bunit/Rendering/BunitRenderer.cs:line 703
at Bunit.Rendering.BunitRenderer.Render(RenderFragment renderFragment) in /_/src/bunit/Rendering/BunitRenderer.cs:line 597
at Bunit.Rendering.BunitRenderer.RenderFragment(RenderFragment renderFragment) in /_/src/bunit/Rendering/BunitRenderer.cs:line 137
at Bunit.BunitContext.RenderInsideRenderTree(RenderFragment renderFragment) in /_/src/bunit/BunitContext.cs:line 230
at Bunit.BunitContext.RenderInsideRenderTree[TComponent](RenderFragment renderFragment) in /_/src/bunit/BunitContext.cs:line 214
at Bunit.BunitContext.Render[TComponent](RenderFragment renderFragment) in /_/src/bunit/BunitContext.cs:line 169
at Bunit.BunitContext.Render[TComponent](Action`1 parameterBuilder) in /_/src/bunit/BunitContext.cs:line 152
at Fact.WhenOpenRendersFlyoutPanel() in C:\Projects\Fact.cs:line 31
at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
Expected behavior:
An implementation for the constructor
Version info:
- bUnit version: 2.6.2
- .NET Runtime and Blazor version: dotnet sdk 10.0.204
- OS type and version: windows 11
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working