IpcMainTests: Properly test for the types of values (must not be JsonElement)

This commit is contained in:
softworkz
2025-11-17 13:11:26 +01:00
parent 8ff875435b
commit b89c08ee96
2 changed files with 20 additions and 3 deletions

View File

@@ -10,7 +10,7 @@
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Nullable>disable</Nullable>
<IsPackable>false</IsPackable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> <!-- https://github.com/Tyrrrz/GitHubActionsTestLogger/issues/5 -->
</PropertyGroup>

View File

@@ -15,10 +15,21 @@ namespace ElectronNET.IntegrationTests.Tests
[Fact(Timeout = 20000)]
public async Task Ipc_On_receives_message_from_renderer()
{
object received = null;
var tcs = new TaskCompletionSource<string>();
await Electron.IpcMain.On("ipc-on-test", obj => tcs.TrySetResult(obj?.ToString() ?? string.Empty));
await Electron.IpcMain.On("ipc-on-test", obj =>
{
received = obj;
tcs.TrySetResult(obj as string);
});
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("require('electron').ipcRenderer.send('ipc-on-test','payload123')");
var result = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5));
received.Should().BeOfType<string>();
received.Should().Be("payload123");
result.Should().Be("payload123");
}
@@ -46,12 +57,18 @@ namespace ElectronNET.IntegrationTests.Tests
[Fact(Timeout = 20000)]
public async Task Ipc_OnSync_returns_value()
{
object received = null;
Electron.IpcMain.OnSync("ipc-sync-test", (obj) =>
{
obj.Should().NotBeNull();
received = obj;
return "pong";
});
var ret = await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("require('electron').ipcRenderer.sendSync('ipc-sync-test','ping')");
received.Should().BeOfType<string>();
received.Should().Be("ping");
ret.Should().Be("pong");
}