We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Created event in not being invoked in unit test (bUnit)

Hi Support,


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,

Marco.


11 Replies

IS Indrajith Srinivasan Syncfusion Team January 25, 2023 10:41 AM UTC

Hi Marco,


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) =>

    {

        createdEventcount++;

        Assert.NotNull("Create event is triggered, when render the component");

        Assert.Equal(1, createdEventcount);

    })));

    await toast.Instance.Show();

}


Please let us know if you face any difficulties,


Regards,

Indrajith



MA Marco January 25, 2023 11:58 AM UTC

Hi  Indrajith,


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.



IS Indrajith Srinivasan Syncfusion Team February 3, 2023 01:55 PM UTC

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.



VJ Vinitha Jeyakumar Syncfusion Team March 29, 2023 07:31 AM UTC

Hi Marco,

We are facing complexity in achieving your requirement. We will provide you with further details as soon as possible.

Regards,
Vinitha




BS Buvana Sathasivam Syncfusion Team March 31, 2023 04:59 PM UTC

Hi Marco,


We have considered the reported issue "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.


Now you can track the status of the reported issue through the feedback below,

https://www.syncfusion.com/feedback/42575/created-event-invoke-from-separate-page-not-triggered-properly-in-the-sftoast


Disclaimer: “Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization.”


Regards,

Buvana S



MA Marco April 7, 2023 12:24 PM UTC

Hi  Buvana,


Thanks a lot for your reply.


I'll keep track of the bug fix status.



Best regards,

Marco.



DR Deepak Ramakrishnan Syncfusion Team April 7, 2023 04:30 PM UTC

Hello Marco,


Thank you for the update. Please do not hesitate to reach out to us if you have any further inquiries.


Thanks,

Deepak R.



MA Marco May 3, 2023 11:55 PM UTC

Hi team,


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.


Best regards,

Marco.



MR Mallesh Ravi Chandran Syncfusion Team May 4, 2023 03:27 PM UTC

Hi Marco,

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.

Regards,

Mallesh 



MA Marco May 5, 2023 12:52 AM UTC

Hi team,


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)
    at 00992dae:0x1d507
    at 00992dae:0x1c935
    at 00992dae:0xe025
    at 00992dae:0xce95
    at 00992dae:0x1a21ff


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.


Best regards,

Marco.



MR Mallesh Ravi Chandran Syncfusion Team May 9, 2023 04:48 PM UTC

Hi Marco,
 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.

 

<script src=https://cdn.syncfusion.com/blazor/21.2.3/syncfusion-blazor.min.js type="text/javascript"></script>

 


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.

Regards,

Mallesh R


Loader.
Up arrow icon