Skip to content

How to test custom events? #423

@majorimi

Description

@majorimi

Hi @egil,

Some time ago we had a chat about Blazor testing. Good to see your package reached v1 :) Now had time to update from Preview-x...

Anyway I'm working on some open sourced Blazor components. One of the components had some issues with Blazor mouse events. As suggested here I implemented "custom" mouse events onmouseleave and onmouseenter.

[EventHandler("onmouseleave", typeof(MouseEventArgs), true, true)]
[EventHandler("onmouseenter", typeof(MouseEventArgs), true, true)]
public static class EventHandlers
{}

And now I want to test this component but run into some issues. Your test framework exposes lots of methods to raise events for a rendered test element e.g.: PointerEnter(), MouseOver(), etc. However I cannot use any of those to my "custom defined" onmouseleave and onmouseenter events. All tests fail with any provided mouse/pointer methods.

Message: 
    Test method Majorsoft.Blazor.Components.PermaLink.Tests.PermaLinkElementTest.PermaLinkElement_should_rendered_ShowPermaLinkIcon_OnHover_correctly threw exception: 
    Bunit.MissingEventHandlerException: The element does not have an event handler for the event 'onmouseover'. It does however have event handlers for these events, 'onmouseenter', 'onmouseleave'.

Any suggestion how can be these custom mouse events triggered? Thanks a lot.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions