jquery doesn't work with jsdom/enzyme

后端 未结 3 1284
时光说笑
时光说笑 2021-01-12 17:00

I have a minimum test react app with following component:

import React from \'react\';
import $ from \'jquery\';

export default class App extends React.Comp         


        
3条回答
  •  被撕碎了的回忆
    2021-01-12 17:12

    I couldn't get Phuong Nguyen's answer to work. I did find the relevant page in the enzyme docs. I ended up with something like, based on the final example on that page:

    const div = global.document.createElement('div');
    global.document.body.appendChild(graphDiv);
    const wrapper = mount(, { attachTo: div });  // same as the other answer
    // clean up after ourselves
    wrapper.detach();
    global.document.body.removeChild(div);
    

提交回复
热议问题