DEV: Fix settledState debug message (#24544)

A properly formatted string instead of circular-JSON error
This commit is contained in:
Jarek Radosz 2023-11-24 12:18:28 +01:00 committed by GitHub
parent 2befff5101
commit 1f2a25331b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -419,10 +419,19 @@ function patchFailedAssertion() {
QUnit.assert.pushResult = function (resultInfo) {
if (!resultInfo.result && !isSettled()) {
const settledState = getSettledState();
let stateString = Object.entries(settledState)
.filter(([, value]) => value === true)
.map(([key]) => key)
.join(", ");
if (settledState.pendingRequestCount > 0) {
stateString += `, pending requests: ${settledState.pendingRequestCount}`;
}
// 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?",
JSON.stringify(getSettledState())
` 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? (${stateString})`
);
}