DEV: ensures relative-ages interval is cleared between tests (#8117)

DEV: ensures relative-ages interval is cleared between tests (#8117)

diff --git a/app/assets/javascripts/discourse/initializers/relative-ages.js.es6 b/app/assets/javascripts/discourse/initializers/relative-ages.js.es6
index 30a0118..aac39ca 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;
+    }
   }
 };

GitHub sha: bbc250cc

1 Like