Support JS invocations that return undefined

This commit is contained in:
Steve Sanderson 2017-12-15 11:40:43 +00:00
parent d1069e2d1e
commit fe6105a902
3 changed files with 22 additions and 2 deletions

View File

@ -37,7 +37,7 @@ namespace MonoSanityClient
return $".NET got exception: {result}"; return $".NET got exception: {result}";
} }
return $".NET received: {result}"; return $".NET received: {(result ?? "(NULL)")}";
} }
} }
} }

View File

@ -7,7 +7,7 @@ namespace Microsoft.Blazor.Browser
{ {
public Renderer() public Renderer()
{ {
WebAssembly.Runtime.EvaluateJavaScript("console.log('Renderer'), 'done'"); WebAssembly.Runtime.EvaluateJavaScript("console.log('Renderer')");
} }
} }
} }

View File

@ -81,6 +81,26 @@ namespace Microsoft.Blazor.E2ETest.Tests
Assert.Contains("at triggerJsException", result); Assert.Contains("at triggerJsException", result);
} }
[Fact]
public void CanEvaluateJsExpressionThatResultsInNull()
{
Navigate("/", noReload: true);
SetValue(Browser, "callJsEvalExpression", "null");
Browser.FindElement(By.CssSelector("#callJs button")).Click();
var result = GetValue(Browser, "callJsResult");
Assert.Equal(".NET received: (NULL)", result);
}
[Fact]
public void CanEvaluateJsExpressionThatResultsInUndefined()
{
Navigate("/", noReload: true);
SetValue(Browser, "callJsEvalExpression", "console.log('Not returning anything')");
Browser.FindElement(By.CssSelector("#callJs button")).Click();
var result = GetValue(Browser, "callJsResult");
Assert.Equal(".NET received: (NULL)", result);
}
private static string GetValue(IWebDriver webDriver, string elementId) private static string GetValue(IWebDriver webDriver, string elementId)
{ {
var element = webDriver.FindElement(By.Id(elementId)); var element = webDriver.FindElement(By.Id(elementId));