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

Mock IJSRuntime "always on", available through JSInterop property on TestContext #237

Closed
egil opened this issue Oct 23, 2020 · 0 comments · Fixed by #247
Closed

Mock IJSRuntime "always on", available through JSInterop property on TestContext #237

egil opened this issue Oct 23, 2020 · 0 comments · Fixed by #247
Labels
enhancement New feature or request input needed When an issue requires input or suggestions
Milestone

Comments

@egil
Copy link
Member

egil commented Oct 23, 2020

.NET5 will bring 1st party components with Blazor that uses JSInterop, and bUnit should support those out of the box (e.g. the Virtualize component). That means providing default planned invocations registered in the mock jsruntime in bUnit for those components.

That requirements leads naturally to an "on by default" or "always on" JSInterop in bUnit, where instead of having to call Services.AddMockJSRuntime(), bUnit's mock jsruntime is registered by default in strict mode. Strict mode is important in this case, as that will make it work much like the current setup, where users custom JSInterop logic is not mocked unless explicitly done so, or if the mock is put in to loose mode.

The MockJSRuntimeInvokeHandler will then be available through a property on the TestContext type, i.e. MockJSRuntimeInvokeHandler JSInterop { get; }, where Mode going forward should be settable.

For backwards compatibility, the existing AddMockJSRuntime() can be marked as obsolete.
And if users want to use their own IJSRuntime and register that through a call to Services.Add****<IJSRuntime>(...) methods, then the builtin bUnit mock will simply be replaced and all will continue to work for those users.

Adding the JSInterop property will also make it easier and cleaner for 3rd party component vendors who want to support testing with bUnit of their components. They can provide an extension method to TestContext that registers handlers for their JS modules/functions, as well as adding any context components to the base render tree (#155). That should allow for a very seamless experience for their users.

RELATED

Add "planned invocations" for built-in types in Blazor.

@egil egil added enhancement New feature or request input needed When an issue requires input or suggestions needs .net 5 labels Oct 23, 2020
@egil egil added this to the v1.0.0 milestone Oct 23, 2020
@egil egil linked a pull request Nov 10, 2020 that will close this issue
9 tasks
@egil egil closed this as completed Nov 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request input needed When an issue requires input or suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant