Skip to content

Commit

Permalink
fix: improve exception message in UnknownEventHandlerIdException
Browse files Browse the repository at this point in the history
  • Loading branch information
egil committed May 26, 2022
1 parent e36e0ad commit 30248f7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/bunit.core/Rendering/UnknownEventHandlerIdException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ private UnknownEventHandlerIdException(SerializationInfo serializationInfo, Stre

private static string CreateMessage(ulong eventHandlerId, EventFieldInfo fieldInfo)
=> $"There is no event handler with ID '{eventHandlerId}' associated with the '{fieldInfo.FieldValue}' event " +
"in the current render tree. This can happen, for example, when using cut.FindAll(), and calling event trigger methods " +
"on the found elements after a re-render of the render tree. The workaround is to use re-issue the cut.FindAll() after " +
"each render of a component, this ensures you have the latest version of the render tree and DOM tree available in your test code.";
$"in the current render tree.{Environment.NewLine}{Environment.NewLine}" +
$"This can happen, for example, when using `cut.FindAll()`, and calling event trigger methods " +
"on the found elements after a re-render of the render tree. The workaround is to use re-issue the `cut.FindAll()` call after " +
$"each render of a component, this ensures you have the latest version of the render tree and DOM tree available in your test code.{Environment.NewLine}{Environment.NewLine}" +
$"This can happen with code like this, `cut.Find(\"button\").Click()`, where the buttons event handler can be removed " +
$"between the time button is found with the Find method and the Click method is triggered. The workaround is to use " +
$"wrap the Find and Click method calls in InvokeAsync, i.e. `cut.InvokeAsync(() => cut.Find(\"button\").Click());`. " +
$"This ensures that there are no changes to the DOM between Find method and the Click method calls.";
}

0 comments on commit 30248f7

Please sign in to comment.