Skip to content

A platform for community discussion. Free, open, simple.

DEV: avoids using document.write (#13858)

Joffrey JAFFEUX32d0467881ab
diff --git a/app/assets/javascripts/discourse/tests/test-helper.js b/app/assets/javascripts/discourse/tests/test-helper.js
index 299a37c7807..f66fa1fe0d9 100644
--- a/app/assets/javascripts/discourse/tests/test-helper.js
+++ b/app/assets/javascripts/discourse/tests/test-helper.js
@@ -8,14 +8,16 @@ document.addEventListener("discourse-booted", () => {
let setupTests = require("discourse/tests/setup-tests").default;
Ember.ENV.LOG_STACKTRACE_ON_DEPRECATION = false;
- document.write(`
- <div id="qunit"></div>
- <div id="qunit-fixture"></div>
-
- <div id="ember-testing-container" style='position: fixed'>
- <div id="ember-testing"></div>
- </div>
- `);
+ document.body.insertAdjacentHTML(
+ "afterbegin",
+ `
+ <div id="qunit"></div>
+ <div id="qunit-fixture"></div>
+ <div id="ember-testing-container" style="position: fixed">
+ <div id="ember-testing"></div>
+ </div>
+ `
+ );
setupTests(config.APP);
start({ setupTestContainer: false });
diff --git a/app/assets/javascripts/wizard/test/test_helper.js b/app/assets/javascripts/wizard/test/test_helper.js
index 9e9d3f99a83..f3ffbfce88f 100644
--- a/app/assets/javascripts/wizard/test/test_helper.js
+++ b/app/assets/javascripts/wizard/test/test_helper.js
@@ -24,14 +24,15 @@
//= require ./wizard-pretender
//= require test-shims
-// Trick JSHint into allow document.write
-let d = document;
-d.write(
- '<div id="ember-testing-container"><div id="ember-testing"></div></div>'
-);
-d.write(
- "<style>#ember-testing-container { position: absolute; background: white; bottom: 0; right: 0; width: 640px; height: 384px; overflow: auto; z-index: 9999; border: 1px solid #ccc; } #ember-testing { zoom: 50%; }</style>"
-);
+document.addEventListener("DOMContentLoaded", function () {
+ document.body.insertAdjacentHTML(
+ "afterbegin",
+ `
+ <div id="ember-testing-container"><div id="ember-testing"></div></div>
+ <style>#ember-testing-container { position: absolute; background: white; bottom: 0; right: 0; width: 640px; height: 384px; overflow: auto; z-index: 9999; border: 1px solid #ccc; } #ember-testing { zoom: 50%; }</style>
+ `
+ );
+});
if (window.Logster) {
Logster.enabled = false;