I have a simple Toast component with an event handler for Created event, as can be seen in the below code snippet:
<SfToast ID="top-banner" @ref="_topBanner" Width="95%" Timeout="10_000" ShowCloseButton="true" Target="@Target">
<ToastPosition X="Center" Y="Top" />
<ToastEvents Created="OnWarningBannerCreatedAsync" />
When running the application, everything works as expected. However, in unit tests (bUnit), the event handler is not invoked, and I couldn't figure out why.
Could you please provide an example of a unit test case where the event handler is invoked?
Thanks and regards,
We have covered the b-unit case for the SfToast created event like the below. Can you try this way to check the created event is invoked in Toast component ?
public async Task CreatedEventTesting()
var createdEventcount = 0;
var toast = RenderComponent<SfToast>(options => options.Add(p => p.Title, "Syncfusion Toast").AddChildContent<ToastEvents>(
displayParameters => displayParameters.Add(s => s.Created, (object args) =>
Assert.NotNull("Create event is triggered, when render the component");
Please let us know if you face any difficulties,
Thanks for your reply but your example does not attend my needs.
In your example, the test method itself is creating a Toast component with an event handler hooked and testing if it is invoked.
In my case, I have a component, with a Toast in it and an event handler method hooked and I need to check if this particular method is invoked during my component's creation (which, in turn, will create the Toast component).
My test method (which is in a .razor file, not in .cs file) looks basically like this:
var cut = Render(@<MyComponent />);
var toast = cut.FindComponent<SfToast>();
Notice that the toast variable is not null, which means the SfToast component has been found (and, thus, was created). However, the Created event handler method hooked to it is not called at any moment during the test.
Am I missing something? If possible, can you please provide an example with a component which contains a SfToast with Created event hooked up to a method and that assures this method is invoked during the component's creation?
Thanks and regards,
Marco, Currently we are validating your reported query with your shared information, and we will update you the details on or before 7th Feb 2023. Until then we appreciate your patience.
Created event invoke from separate page not triggered properly in the SfToast component" as a bug from our end and the fix for the issue will be included with our upcoming patch release at the end of April, 2023
Thanks a lot for your reply.
I'll keep track of the bug fix status.
Thank you for the update. Please do not hesitate to reach out to us if you have any further inquiries.
The bug is still in "scheduled" status, but I just downloaded the latest SP Release (version 21.2.3) and everything is working as expected now, so, it seems to me the bug can be closed.
We are pleased to hear that the latest SP release has resolved the issue you were facing and that everything is now working as expected. Thank you for keeping us informed.
If you have any additional questions or concerns, please do not hesitate to contact us.
Although the issue regarding the unit test has been fixed, another one has arised. As soon as the component is created, the below message is printed on the browser console:
Uncaught (in promise) Error: System.ArgumentException: The type 'SfToast' does not contain a public invokable method with [JSInvokableAttribute("CreatedEvent")].
at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.GetCachedMethodInfo(:7196/IDotNetObjectReference objectReference, String methodIdentifier)
at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.InvokeSynchronously(:7196/JSRuntime jsRuntime, DotNetInvocationInfo& callInfo, IDotNetObjectReference objectReference, String argsJson)
at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.BeginInvokeDotNet(:7196/JSRuntime jsRuntime, DotNetInvocationInfo invocationInfo, String argsJson)
at Object.endInvokeDotNetFromJS (blazor.webassembly.js:1:3549)
at Object.Xt [as endInvokeDotNetFromJS] (blazor.webassembly.js:1:63263)
at Object.Gt [as invokeJSFromDotNet] (blazor.webassembly.js:1:62760)
at Object.Ii (dotnet.7.0.5.cxbzzxr9h6.js:5:71974)
at _mono_wasm_invoke_js_blazor (dotnet.7.0.5.cxbzzxr9h6.js:14:103886)
This seems to be a harmless issue (at least for my specific use case), but I understand it needs to be fixed anyway,. BTW, I tested with the official release (21.1.35) and it doesn't happen.
We suspect that the issue may be related to the cache not being cleared. To resolve this, we recommend that you try using the CDN link provided below.
Using this link can help resolve the issue. If you continue to face the issue even after using the CDN link, please let us know, and we will be happy to assist you further.