Skip to content

Commit 8c8dbeb

Browse files
committed
Fix JSExport test.
1 parent c32a368 commit 8c8dbeb

File tree

3 files changed

+9
-17
lines changed

3 files changed

+9
-17
lines changed

src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSExportTest.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -440,14 +440,8 @@ public async Task InternalsVisibleToDoesntBreak()
440440
[Fact]
441441
public async void JSExportCompletedTaskReturnsResolvedPromise()
442442
{
443-
try
444-
{
445-
await JavaScriptTestHelper.InvokeReturnCompletedTask();
446-
}
447-
catch (Exception ex)
448-
{
449-
Assert.Fail($"JSExport failed with {ex}");
450-
}
443+
string result = await JavaScriptTestHelper.InvokeReturnCompletedTask();
444+
Assert.Equal("resolved", result);
451445
}
452446
}
453447
}

src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ public static Exception EchoException([JSMarshalAs<JSType.Error>] Exception arg1
446446
internal static partial Task ReturnResolvedPromise();
447447

448448
[JSImport("invokeReturnCompletedTask", "JavaScriptTestHelper")]
449-
internal static partial Task InvokeReturnCompletedTask();
449+
internal static partial Task<string> InvokeReturnCompletedTask();
450450

451451
[JSExport]
452452
internal static Task ReturnCompletedTask()

src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,12 @@ export function returnResolvedPromise() {
252252

253253
export async function invokeReturnCompletedTask() {
254254
const JavaScriptTestHelper = dllExports.System.Runtime.InteropServices.JavaScript.Tests.JavaScriptTestHelper;
255-
const p = JavaScriptTestHelper['ReturnCompletedTask'];
256-
await Promise.race([p, delay(100)])
257-
.then(() => {
258-
console.log("Promise is resolved."); // to be removed
259-
})
260-
.catch(() => {
261-
error("Promise is rejected or timed out waiting for resolving.");
262-
});
255+
const p = JavaScriptTestHelper['ReturnCompletedTask']();
256+
const result = await Promise.race([
257+
p.then(() => "resolved"),
258+
delay(1000).then(() => "timeout")
259+
]);
260+
return result;
263261
}
264262

265263
export function invokeStructClassRecords(arg1) {

0 commit comments

Comments
 (0)