Files
pjax/tests/lib/eval-scripts.js
Behind The Math 33519f01ae Fix evalScripts()
* Set the id of the insert <script>.
* Check if the <script> still exists before trying to remove it.
2018-11-21 21:33:41 -05:00

42 lines
1.2 KiB
JavaScript

var tape = require("tape")
var evalScript = require("../../lib/eval-script")
tape("test evalScript method", function(t) {
document.body.className = ""
var script = document.createElement("script")
script.innerHTML = "document.body.className = 'executed'"
t.equal(document.body.className, "", "script hasn't been executed yet")
evalScript(script)
t.equal(document.body.className, "executed", "script has been properly executed")
script.innerHTML = "document.write('failure')"
var bodyText = "document.write hasn't been executed"
document.body.text = bodyText
evalScript(script)
t.equal(document.body.text, bodyText, "document.write hasn't been executed")
t.end()
})
tape.only("evalScript should not throw an error if the script removed itself", function(t) {
var script = document.createElement("script")
script.id = "myScript";
script.innerHTML = "const script = document.querySelector('#myScript');" +
"script.parentNode.removeChild(script);";
try {
evalScript(script);
t.pass("Missing script tested successfully");
} catch (e) {
console.error(e);
t.fail("Attempted to remove missing script");
}
t.end();
})