Skip to content

TelerikTestContext replacing IJSRuntime not ideal #258

@egil

Description

@egil

I noticed that TelerikTestContext and TelerikTestContextWithActualRoot are replacing bUnits built-in IJSRuntime with a mock. While it does work, there are a bunch of edge cases and 1st party components that bUnit's version is configured to handle out of the box (e.g. the Virtualize component), so a better approach would be to set up everything that is needed to render Telerik components directly.

There are a bunch of ways to achieve this, so I am curious what // mock the JS Interop service, you cannot use the one coming from the context refers to and will gladly help resolve any issues that are (if possible). If possible, outline the JSInterop requirements and I can help set things up.

public TelerikTestContext()
{
// mock the JS Interop service, you cannot use the one coming from the context
var jsRuntimeMock = Mock.Create<IJSRuntime>();
// you can also register a real one for actual localization to test that too
var localizerMock = Mock.Create<ITelerikStringLocalizer>();
// make sure JS Interop is available first
Services.AddSingleton(jsRuntimeMock);
// add the Telerik Blazor services like in a regular app
Services.AddTelerikBlazor();
Services.AddSingleton(localizerMock);
}

Related: bUnit-dev/bUnit#1175

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions