How do I test the add script feature in Jest?

  • 0
    There is a function

    addScript = ( _src) => {
    script     = window.document.createElement('script');
                script.src = _src;
                window.document.head.appendChild(script);}


    In the test, I call it (the file with the function is connected at the top)
    test('addScript', () => {
    addScript('balblabla'); 
    const tag2 = window.document.head.querySelectorAll('script');
            console.log(tag2.length);
    });


    The log produces 0. Why?
    JavaScript Anonymous, Dec 29, 2018

  • 0 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!