-
The Toast Service OnShow throws a new popup window which is not part of the HTML being rendered.
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 9 replies
-
Hi Anita Can you share an example of the test setup, the component under test, and the test (assertion) you are trying to write? @chrissainty might also be able to share some insights about the Toast component or have an idea about how to test a component that uses it. |
Beta Was this translation helpful? Give feedback.
-
@egil I was able to get my code that used Moq to mock IToastService to work. It was a minor bug in my code which I since figured out (had an incorrect type as the second parameter to ShowToast). |
Beta Was this translation helpful? Give feedback.
-
Here is a relevant portion of my initial quick fix (moving the Mock to a different .cs file as I have various other Mock files) using Moq;
// Arrange
var toastMoq = new Mock<IToastService>();
toastMoq.Setup(t => t.ShowToast(It.Is<ToastLevel>(t => t == ToastLevel.Success), It.IsAny<RenderFragment>(), It.IsAny<string>())).Verifiable();
using var ctx = new TestContext();
ctx.Services.AddSingleton<IToastService>(toastMoq.Object);
// Act
......
var cut = ctx.RenderComponent<MyPage>();
// Add Resource Group Name and Owner Name to the Form
cut.Find("input[name=resgroupname]").Change("TestResourceGroup");
cut.Find("input[name=ownername]").Change("TestOwner");
Action<List<AzureResourceGroup>> OnValidSubmit = _ => { };
var cut1 = ctx.RenderComponent<MyTool.Pages.Azure>(parameters => parameters
.Add(p => p.AzureResourceGroupsChanged, OnValidSubmit)
);
.....
// Assert
cut.Find("form").Submit();
toastMoq.Verify(); |
Beta Was this translation helpful? Give feedback.
Here is a relevant portion of my initial quick fix (moving the Mock to a different .cs file as I have various other Mock files)