jeudi 11 avril 2019

test my final javascript library with mocked document

We have our JS library we add to pages, then the script adds another script, creates an iframes and listen for messages from the iframe.

So the library interacts with the document object for appending a new script element and a new iframe element.

I would like to mock a document that has my script loads in it and to mock the iframe creation

So I could mock messages from the iframe.

The code snippet pages place so our script gets loaded:

(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);
})();

you can see this snippet creates a script and appends it to the document

Any help is appreciated

Aucun commentaire:

Enregistrer un commentaire