Creating HTML elements for javascript testing

后端 未结 1 1596
面向向阳花
面向向阳花 2021-01-24 08:08

So i have a particular problem, inside my react component i used commands like these:

document.getElementById(\'modalsContainer\').appendChild(recognitionProfile         


        
1条回答
  •  有刺的猬
    2021-01-24 08:33

    Creating DOM elements in your enzyme tests:

    So guys, to create DOM elements in your test, it's actually really simple and you type it just as you would in vanilla javascript, with the global keyword:

    it('Should hide the modal', function() {
            var wrapper, instance;
            var modalsContainer = global.document.createElement('div');
            var recognitionProfileZoom = global.document.createElement('div');
            var categoryZoom = global.document.createElement('div');
    
            modalsContainer.id = 'modalsContainer';
            recognitionProfileZoom.id = 'recognitionProfileZoom';
            categoryZoom.id = 'categoryZoom';
            global.document.body.appendChild(modalsContainer);
            global.document.body.appendChild(recognitionProfileZoom);
            global.document.body.appendChild(categoryZoom);  
    

    After this is done you can expect values, and use the DOM elements normally.

    0 讨论(0)
提交回复
热议问题