DEV: Resolve flaky test caused by requestAnimationFrame use (#20396)

We need to register a waiter so that any calls to `await settled()` will wait for the `requestAnimationFrame` call to return. Wrapping in `DEBUG` as well as `isTesting()` means that this extra logic will be totally optimized out of production builds.
This commit is contained in:
David Taylor 2023-02-21 18:02:04 +00:00 committed by GitHub
parent 3cadeaf90f
commit 207c0dd88c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 3 deletions

View File

@ -10,6 +10,9 @@ import ItsATrap from "@discourse/itsatrap";
import RerenderOnDoNotDisturbChange from "discourse/mixins/rerender-on-do-not-disturb-change";
import { observes } from "discourse-common/utils/decorators";
import { topicTitleDecorators } from "discourse/components/topic-title";
import { isTesting } from "discourse-common/config/environment";
import { DEBUG } from "@glimmer/env";
import { registerWaiter, unregisterWaiter } from "@ember/test";
const SiteHeaderComponent = MountWidget.extend(
Docking,
@ -54,9 +57,18 @@ const SiteHeaderComponent = MountWidget.extend(
},
_animateOpening(panel) {
window.requestAnimationFrame(
this._setAnimateOpeningProperties.bind(this, panel)
);
let waiter;
if (DEBUG && isTesting()) {
waiter = () => true;
registerWaiter(waiter);
}
window.requestAnimationFrame(() => {
this._setAnimateOpeningProperties(panel);
if (DEBUG && isTesting()) {
unregisterWaiter(waiter);
}
});
},
_setAnimateOpeningProperties(panel) {