我正在尝试创建一个 mochajs 测试来检测 script.onload 事件是否已执行或 script.onerror。我已经设置测试来检测 DOM 中是否存在脚本,但不确定如何检查实际加载。
describe("Load external ABC Library", function() {
var h = document.getElementsByTagName('head')[0];
var s = document.createElement('script');
s.src="http://host.com/script.js";
s.id="abc";
s.async=false;
h.appendChild(s);
var l = document.getElementById('abc');
it.skip("is in the DOM", function () {
expect(l).to.not.equal(null);
console.log('is in the DOM was skipped');
});
it("is a child of the head", function () {
expect(l.parentElement).to.equal(document.head);
});
});