Replies: 1 comment 3 replies
-
Hi @thalaeg Think you need to update your test code to look like this: public void NewButton_DefaultsToButtonTag()
{
// you do not have to specify the "import" identifier. Instead, just provide the module name.
var jsModule = JSInterop.SetupModule("./_content/HeadlessUI/common.js");
// When no parameters are specified to the SetupVoid method, besides the function name, it will match parameter kinds.
// runtimeHandler.SetVoidResult(); this can be done anywhere in this method below this point.
// to keep the test simple, you can set it here
jsModule.SetupVoid("preventDefaultKeyBehaviorOnKeys").SetVoidResult();
// alternative to the line above is to simply set the jsModule to run in loose mode, that means it will match all invocations to it
// if you do this, you do not need the SetupVoid line above.
jsModule.Mode = JSRuntimeMode.Loose;
var component = RenderComponent<HUIButton>();
var myButton = component.Find("button");
Assert.NotNull(myButton );
}
The problem is that the To verify that, you can do soemthing like this: // assuming myButton is the button that should be passed as an element reference
var myButton = component.Find("button");
var invocation = jsModule.VerifyInvoke("preventDefaultKeyBehaviorOnKeys");
invocation.Arguments[0].ShouldBeElementReferenceTo(myButton);
// You can inspect the other arguments pass to the method by looking into the arguments array. And yes, that JSInterop documentation does need some love to make these things clearer! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a test like follows
This is testing this code. Code that I know works in production. You'll see the buttonElement is an HtmlElement (a class that inherits from Component Base. It has access to the ElementReference I pass in).
This is how I believe this should work. I pass in my identifier and args in the Test, yet the params aren't passed through or recognized as the same.
I get the following error message
What gives?
In the mean time I just have used
SetupVoid()
with no arguments and that works but I would prefer to be specific.Beta Was this translation helpful? Give feedback.
All reactions