Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: pass Activator.CreateInstance exception as inner exception #2703

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Playwright.Tests/PageEvaluateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public async Task ShouldWork()
Assert.AreEqual(21, result);
}

[PlaywrightTest()]
public async Task ShouldSerializeArguments()
{
int result = await Page.EvaluateAsync<int>("a => a.m * a.n", new { m = 7, n = 3 });
Expand Down Expand Up @@ -656,6 +657,7 @@ public async Task ShouldJsonValueDate()
Assert.AreEqual(new DateTime(2020, 05, 27, 1, 31, 38, 506), result.date);
}

[PlaywrightTest()]
public async Task ShouldSerializeEnumProperty()
{
int result = await Page.EvaluateAsync<int>("a => a.TestEnum", new ClassWithEnumProperty());
Expand Down Expand Up @@ -718,4 +720,15 @@ public async Task ShouldParseTypeProperties()
Assert.AreEqual(600, result.Width);
Assert.AreEqual(400, result.Height);
}

#if NET6_0_OR_GREATER
private record ShapeRecord(int Width, int Height);

[PlaywrightTest()]
public async Task ShouldParseRecordProperties()
{
var exception = await PlaywrightAssert.ThrowsAsync<PlaywrightException>(() => Page.EvaluateAsync<ShapeRecord>("() => ({ width: 600, height: 400 })"));
Assert.IsInstanceOf<MissingMethodException>(exception.InnerException);
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ private static object ToExpectedType(object parsed, Type t, IDictionary<object,
{
objResult = Activator.CreateInstance(t);
}
catch (Exception)
catch (Exception ex)
{
throw new PlaywrightException("Return type mismatch. Expecting " + t.ToString() + ", got Object");
throw new PlaywrightException("Return type mismatch. Expecting " + t.ToString() + ", got Object", ex);
}
visited.Add(parsed, objResult);

Expand Down