Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(testing): use correct JSruntime in the sample test project #259

Merged
merged 4 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ public IRenderedComponent<TelerikRootComponent> RootComponent

public TelerikTestContext()
{
// mock the JS Interop service, you cannot use the one coming from the context
var jsRuntimeMock = Mock.Create<IJSRuntime>();
JSInterop.SetupVoid(x => x.Identifier.StartsWith("TelerikBlazor", StringComparison.InvariantCultureIgnoreCase));
JSInterop.Setup<string>(x => x.Identifier.StartsWith("TelerikBlazor", StringComparison.InvariantCultureIgnoreCase)).SetResult(string.Empty);
JSInterop.Setup<bool>(x => x.Identifier.StartsWith("TelerikBlazor", StringComparison.InvariantCultureIgnoreCase)).SetResult(default);
JSInterop.Setup<double>(x => x.Identifier.StartsWith("TelerikBlazor", StringComparison.InvariantCultureIgnoreCase)).SetResult(default);

// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public IRenderedComponent<TelerikRootComponent> RootComponent

public TelerikTestContextWithActualRoot()
{
// mock the JS Interop service, you cannot use the one coming from the context
var jsRuntimeMock = Mock.Create<IJSRuntime>();
JSInterop.SetupVoid(x => x.Identifier.StartsWith("TelerikBlazor", StringComparison.InvariantCultureIgnoreCase));
JSInterop.Setup<string>(x => x.Identifier.StartsWith("TelerikBlazor", StringComparison.InvariantCultureIgnoreCase)).SetResult(string.Empty);
JSInterop.Setup<bool>(x => x.Identifier.StartsWith("TelerikBlazor", StringComparison.InvariantCultureIgnoreCase)).SetResult(default);
JSInterop.Setup<double>(x => x.Identifier.StartsWith("TelerikBlazor", StringComparison.InvariantCultureIgnoreCase)).SetResult(default);

// 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);
Expand Down