How to get BUnit JSInterop?

40 views Asked by At

According to the BUnit documentation this should be available by default. But in my Unit test Microsoft.JSInterop is a namespace, not a class where Setup can be called on. I've also tried BUnitJSInterop. Am I missing a using? Or something else?

Maybe I need to be in a test context? I'm already writing this code from an XUnit [Fact] attributed method. I don't think BUnit has any context modifiers.

1

There are 1 answers

0
Link On BEST ANSWER

The BunitJSInterop type is member of the TestContext, see our API documentation.

That said you can easily access the property like this:

public class MyTests : TestContext
{
  [Fact]
  public void Test001()
  {
    JSInterop.SetupVoid("myfunc", "myarg").SetVoidResult();

Your issue might arise as your class is not directly inheriting from TestContext but is newed up in your test:

public class MyTest
{
  [Fact]
  public void Test001()
  {
    using var ctx = new TestContext();
    ctx.JSInterop.SetupVoid("myfunc", "myarg").SetVoidResult();