Skip to content

GAUD-9420: delay event to try and fix flaky test#6566

Open
dlockhart wants to merge 1 commit intomainfrom
GAUD-9420/alert-toast-fix-2
Open

GAUD-9420: delay event to try and fix flaky test#6566
dlockhart wants to merge 1 commit intomainfrom
GAUD-9420/alert-toast-fix-2

Conversation

@dlockhart
Copy link
Member

Looks like the original fix in #6559 didn't do the trick, so this is another attempt.

My new theory is that because dispatching events is synchronous, that the test doing a clickElem and then await oneEvent one line after the other is missing the re-firing of the new event. So just like we do in many other places, this wraps the dispatching of the new event in a timeout.

@dlockhart dlockhart requested a review from a team as a code owner February 5, 2026 21:39
@github-actions
Copy link
Contributor

github-actions bot commented Feb 5, 2026

Thanks for the PR! 🎉

We've deployed an automatic preview for this PR - you can see your changes here:

URL https://live.d2l.dev/prs/BrightspaceUI/core/pr-6566/

Note

The build needs to finish before your changes are deployed.
Changes to the PR will automatically update the instance.

_handleButtonPress(e) {
e.stopPropagation();
this.dispatchEvent(new CustomEvent('d2l-alert-toast-button-press'));
setTimeout(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean we might end up delaying more events?

I always find this logic non-intuitive, in that it's relying on the internals of clickElem delaying things long enough for oneEvent to do its wire-up before the event is dispatched. But I appreciate the simplicity of it.

clickElem(closeButton);
await oneEvent(alert, 'd2l-alert-close');

This is more intuitive to me since it eliminates that internal timing dependency.

const p = new Promise(resolve => {
    closeButton.addEventListener('some-event', resolve, { once: true });
});
clickElem(closeButton);
await p;

Maybe there is a way we can set up the helpers to do the wire-up in this order, without consumers needing to write all this code...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, maybe we should add the setTimeout in clickElem instead, since it seems like it's just to support the order of ops in the test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants