Skip to content

Add support for Blazors <InputFile> component #317

Closed

Description

@egil

Render a component with the <InputFile> component inside requires additional set up, that bUnit should provide out of the box.

The current solution is to provide a mock of a IOptions<RemoteBrowserFileStreamOptions> and configure the JSInterop to handle the <InputFile> components JSInterop invocation. E.g.

var optionsMock = Substitute.For<IOptions<RemoteBrowserFileStreamOptions>>();
Services.AddSingleton<IOptions<RemoteBrowserFileStreamOptions>>(optionsMock);
JSInterop.SetupVoid("Blazor._internal.InputFile.init", x => true);

This will allow the component to render, but additional steps might be needed to test the "input" part of the component.

Related: #314

Activity

  1. added
    enhancementNew feature or request
    investigateThis issue require further investigation before closing.
    on Feb 6, 2021
  2. egil commented on Jun 2, 2021

    @egil
    MemberAuthor

    This discussion post has a complete example for how to test a component that uses the InputFile component: #415

  3. linkdotnet commented on May 9, 2022

    @linkdotnet
    Collaborator

    To all who are subscribed to that topic: There will be a new nightly build coming out addressing that exact issue. From now on you can use a convenient function to setup InputFile:

    // Arrange
    var context = new TestContext();
    var cut = context.RenderComponent<MyComponent>();
    // Arrange the file which gets uploaded
    var fileToUpload = InputFileContent.CreateFromText("Hello World", "MyFile.txt");
    
    // Find the InputFile component and upload the file
    cut.FindComponent<InputFile>().UploadFiles(fileToUpload);
    
    // Assert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestinvestigateThis issue require further investigation before closing.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions