DEV: prevents test timeout (#12631)
Clock manipulation seems not reliable in component tests. This blog post does a great job of explaining it: https://dockyard.com/blog/2018/04/18/bending-time-in-ember-tests Sadly, we don't have all the "recent" ember test helpers and can't use things like `getSettledState()`. For now this pattern seems the most reliable and easy to apply, albeit not great. Note if you wish to reproduce the current timeout, the following command should do it: `QUNIT_SEED=215263717493121190480103670124734840282 rake qunit:test`
This commit is contained in:
+11
-19
@@ -1,30 +1,19 @@
|
||||
import componentTest, {
|
||||
setupRenderingTest,
|
||||
} from "discourse/tests/helpers/component-test";
|
||||
import sinon from "sinon";
|
||||
import {
|
||||
discourseModule,
|
||||
fakeTime,
|
||||
publishToMessageBus,
|
||||
queryAll,
|
||||
} from "discourse/tests/helpers/qunit-helpers";
|
||||
import hbs from "htmlbars-inline-precompile";
|
||||
import { later } from "@ember/runloop";
|
||||
|
||||
let clock = null;
|
||||
discourseModule(
|
||||
"Integration | Component | software-update-prompt",
|
||||
function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
clock = fakeTime("2019-12-10T08:00:00", "Australia/Brisbane", true);
|
||||
});
|
||||
|
||||
hooks.afterEach(function () {
|
||||
clock.restore();
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
componentTest(
|
||||
"software-update-prompt gets correct CSS class after messageBus message",
|
||||
{
|
||||
@@ -36,6 +25,7 @@ discourseModule(
|
||||
.length === 0,
|
||||
"it does not have the class to show the prompt"
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
queryAll("div.software-update-prompt")[0].getAttribute(
|
||||
"aria-hidden"
|
||||
@@ -46,13 +36,15 @@ discourseModule(
|
||||
|
||||
publishToMessageBus("/global/asset-version", "somenewversion");
|
||||
|
||||
clock.tick(1000 * 60 * 24 * 60 + 10);
|
||||
|
||||
assert.ok(
|
||||
queryAll("div.software-update-prompt.require-software-refresh")
|
||||
.length === 1,
|
||||
"it does have the class to show the prompt"
|
||||
);
|
||||
const done = assert.async();
|
||||
later(() => {
|
||||
assert.ok(
|
||||
queryAll("div.software-update-prompt.require-software-refresh")
|
||||
.length === 1,
|
||||
"it does have the class to show the prompt"
|
||||
);
|
||||
done();
|
||||
}, 10);
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user