mirror of
https://github.com/discourse/discourse.git
synced 2024-12-02 13:39:36 -06:00
DEV: Add hint when qunit assertion fails and app is unsettled (#17984)
This commit is contained in:
parent
707034bc75
commit
c63580b226
@ -13,7 +13,12 @@ import pretender, {
|
||||
} from "discourse/tests/helpers/create-pretender";
|
||||
import { resetSettings } from "discourse/tests/helpers/site-settings";
|
||||
import { getOwner, setDefaultOwner } from "discourse-common/lib/get-owner";
|
||||
import { setApplication, setResolver } from "@ember/test-helpers";
|
||||
import {
|
||||
getSettledState,
|
||||
isSettled,
|
||||
setApplication,
|
||||
setResolver,
|
||||
} from "@ember/test-helpers";
|
||||
import { setupS3CDN, setupURL } from "discourse-common/lib/get-url";
|
||||
import Application from "../app";
|
||||
import MessageBus from "message-bus-client";
|
||||
@ -372,6 +377,7 @@ export default function setupTests(config) {
|
||||
|
||||
setupToolbar();
|
||||
reportMemoryUsageAfterTests();
|
||||
patchFailedAssertion();
|
||||
}
|
||||
|
||||
function getUrlParameter(name) {
|
||||
@ -400,3 +406,19 @@ function replaceUrlParameter(name, value) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function patchFailedAssertion() {
|
||||
const oldPushResult = QUnit.assert.pushResult;
|
||||
|
||||
QUnit.assert.pushResult = function (resultInfo) {
|
||||
if (!resultInfo.result && !isSettled()) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(
|
||||
"ℹ️ Hint: when the assertion failed, the Ember runloop was not in a settled state. Maybe you missed an `await` further up the test? Or maybe you need to manually add `await settled()` before your assertion?",
|
||||
getSettledState()
|
||||
);
|
||||
}
|
||||
|
||||
oldPushResult.call(this, resultInfo);
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user