From bbc250cc3510f52be843b23e7ae2d36a3eab8206 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Tue, 1 Oct 2019 22:18:26 +0200 Subject: [PATCH] DEV: ensures relative-ages interval is cleared between tests (#8117) --- .../discourse/initializers/relative-ages.js.es6 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/initializers/relative-ages.js.es6 b/app/assets/javascripts/discourse/initializers/relative-ages.js.es6 index 30a0118d3e8..aac39ca3c6d 100644 --- a/app/assets/javascripts/discourse/initializers/relative-ages.js.es6 +++ b/app/assets/javascripts/discourse/initializers/relative-ages.js.es6 @@ -3,9 +3,17 @@ import { updateRelativeAge } from "discourse/lib/formatter"; // Updates the relative ages of dates on the screen. export default { name: "relative-ages", - initialize: function() { - setInterval(function() { + + initialize() { + this._interval = setInterval(function() { updateRelativeAge($(".relative-date")); }, 60 * 1000); + }, + + teardown() { + if (this._interval) { + clearInterval(this._interval); + this._interval = null; + } } };