GAUD-9420: delay event to try and fix flaky test#6566
Conversation
|
Thanks for the PR! 🎉 We've deployed an automatic preview for this PR - you can see your changes here:
Note The build needs to finish before your changes are deployed. |
| _handleButtonPress(e) { | ||
| e.stopPropagation(); | ||
| this.dispatchEvent(new CustomEvent('d2l-alert-toast-button-press')); | ||
| setTimeout(() => { |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
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
clickElemand thenawait oneEventone 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.