You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How can a Blazored Modal be unit tested? (I'm using the bUnit framework.)
My modal component has a CascadingParameter BlazoredModalInstance. Clicking "OK" calls BlazoredModalInstance.CloseAsync(), and cancelling calls BlazoredModalInstance.CancelAsync(). The Blazored Modal works fine in my application. (Thanks for the good work!)
Since BlazoredModalInstance is a class, I can't use a mock to check if CloseAsync or CancelAsync have been called.
I can construct a BlazoredModalInstance object in the test and supply it as a parameter to a surrounding my modal component under test, but when e.g. CloseAsync is called, I get a NullReferenceException at Blazored.Modal.BlazoredModalInstance.d__72.MoveNext().
Do I need set up the initial state of this test BlazoredModalInstance object more, e.g., by calling some other methods on it?
I had hoped for something more like IModalService. I am able to unit test the code to show my modal (e.g., IModalService.Show). It's very easy to mock IModalService and IModalReference in order to test my modal from the "outside". But I can't figure out how to test the modal from the "inside".
There isn't any testing integrations with bUnit at the moment. I plan to add one as I have with Blazored Toast and Local/Session Storage but I haven't been able to find the time yet.
How can a Blazored Modal be unit tested? (I'm using the bUnit framework.)
My modal component has a CascadingParameter BlazoredModalInstance. Clicking "OK" calls BlazoredModalInstance.CloseAsync(), and cancelling calls BlazoredModalInstance.CancelAsync(). The Blazored Modal works fine in my application. (Thanks for the good work!)
Since BlazoredModalInstance is a class, I can't use a mock to check if CloseAsync or CancelAsync have been called.
I can construct a BlazoredModalInstance object in the test and supply it as a parameter to a surrounding my modal component under test, but when e.g. CloseAsync is called, I get a NullReferenceException at Blazored.Modal.BlazoredModalInstance.d__72.MoveNext().
Do I need set up the initial state of this test BlazoredModalInstance object more, e.g., by calling some other methods on it?
I had hoped for something more like IModalService. I am able to unit test the code to show my modal (e.g., IModalService.Show). It's very easy to mock IModalService and IModalReference in order to test my modal from the "outside". But I can't figure out how to test the modal from the "inside".
Originally posted by @linestandard in #311
The text was updated successfully, but these errors were encountered: