Skip to content

detect an EventCallback #528

@drma-tech

Description

@drma-tech

I have the following situation

<EditForm Model="Variable" OnValidSubmit="OnValidSubmit">
</EditForm>
[Parameter]
public Variable Variable { get; set; } = new();
[Parameter]
public EventCallback Updated { get; set; }
protected async Task OnValidSubmit(EditContext context)
{
    try
    {
        //code
        await Updated.InvokeAsync();
    }
    catch (Exception ex)
    {
        ex.ProcessError(Toaster, Logger, context.Model);
    }
}

and the following test

Action UpdatedHandler = () => { };

var model = FakeData.GetVariable().Generate();

var cut = ctx.RenderComponent<VariableData>(parameters => parameters
    .Add(p => p.Updated, UpdatedHandler)
    .Add(p => p.Variable, model)
);

cut.FindByTag("form").Submit();

Assert.AreEqual(true, cut.Instance.Updated.HasDelegate);

I know I can have any attribute and fill it with a value and test it, but if I don't want to go that way.
is there a way to test if an event has fired? in this case Update event.

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