2

In a project, I'm handling a service written in C#, that when called, will return a generated Javascript function. Think of it like this, but more complex:

string GetJSFunction(int value) {
return "function my_js_function() { return " + value.ToString() + "; }"
}

I want to do unit tests (in C#) to check that the methods I'm generating are valid JS code and behave correctly. Are there any "simple" way to do this? I've thought of doing the following:

  • write the JS function to a temporary html page
  • use a headless browser to call the webpage, call the JS script
  • parse and check the result

Is there a simpler way?

lezebulon
  • 7,607
  • 11
  • 42
  • 73
  • Have a look at https://stackoverflow.com/questions/4744105/parse-and-execute-js-by-c-sharp This question is a duplicate. – BossCode Mar 25 '21 at 23:49

0 Answers0