Skip to content

Commit 2d252a2

Browse files
authored
Page.WaitForFunctionAsync should work with multiline strings (#914)
* Page.WaitForFunctionAsync should work with multiline strings * Add tests
1 parent b1b8982 commit 2d252a2

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

lib/PuppeteerSharp.Tests/PageTests/WaitForTests.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ public async Task ShouldTimeout()
5656
Assert.True((DateTime.Now - startTime).TotalMilliseconds > timeout / 2);
5757
}
5858

59+
[Fact]
60+
public async Task ShouldWorkWithMultilineBody()
61+
{
62+
var result = await Page.WaitForExpressionAsync(@"
63+
(() => true)()
64+
");
65+
Assert.True(await result.JsonValueAsync<bool>());
66+
}
67+
5968
[Fact]
6069
public async Task ShouldWaitForPredicate()
6170
{
@@ -66,8 +75,6 @@ public async Task ShouldWaitForPredicate()
6675

6776
[Fact]
6877
public async Task ShouldWaitForPredicateWithArguments()
69-
{
70-
await Page.WaitForFunctionAsync("(arg1, arg2) => arg1 !== arg2", new WaitForFunctionOptions(), 1, 2);
71-
}
78+
=> await Page.WaitForFunctionAsync("(arg1, arg2) => arg1 !== arg2", new WaitForFunctionOptions(), 1, 2);
7279
}
7380
}

lib/PuppeteerSharp/WaitTask.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ internal WaitTask(
130130
}
131131

132132
_frame = frame;
133-
_predicateBody = isExpression ? $"return {predicateBody}" : $"return ( {predicateBody} )(...args)";
133+
_predicateBody = isExpression ? $"return ({predicateBody})" : $"return ({predicateBody})(...args)";
134134
_polling = polling;
135135
_pollingInterval = pollingInterval;
136136
_timeout = timeout;

0 commit comments

Comments
 (0)