Skip to content

Mocking components in render tree #53

@egil

Description

@egil

Hard to arrange tests
The issue #52 and #38 is an example of a test that is hard to "arrange" because a sub-component of the component under test, employs a lot of JSInterop to do its work. It could also be a 3rd party component that is used in the component under test, that has a dependency on a service, that the test would have to provide a mock of to get a test to work as expected.

Describe the solution you'd like
It would be nice to be able to mock out the sub-component that has external dependencies that is not important to the test. That would make the test much easier to arrange, being able to mock or replace a sub-component in a render tree.

It is not clear if it will be possible to mock or replace a component. A few problems I see:

  1. Components are normally regular (partial) classes. Those are not easy to mock by tools such as Moq.
  2. To properly mock a component, it would have to be replaced/mocked before the component is instantiated by the Renderer, through a RenderTreeBuilder.OpenComponent(). It is possible that the same trick we have discussed in Enable shallow rendering mode #17 could be repurposed, iff it is possible to create a mocked instance of the component.

Additional context
This could be related to #17.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions