使用模拟文档测试我的最终JavaScript库

时间:2019-04-11 16:36:41

标签: javascript testing mocking ui-automation

我们有添加到页面的JS库, 然后脚本添加了另一个脚本, 创建一个iframe 并收听来自iframe的消息。

因此,该库与document对象进行交互,以附加新的脚本元素和新的iframe元素。

我想模拟加载了脚本的文档 并模拟iframe的创建

所以我可以模拟来自iframe的消息。

放置代码段页面,以便加载脚本:

(function () {
    var t = document.createElement('script');
    t.async = true;
    t.setAttribute("data-track-key", 'someKey');
    t.setAttribute("data-url", 'local.example.io');
    t.setAttribute("data-track", false);
    t.src = 'example.com/track.js';
    document.body.appendChild(t);
})();

您可以看到此代码段创建了一个script并将其附加到document

感谢您的帮助

0 个答案:

没有答案