jquery doesn't work with jsdom/enzyme

后端 未结 3 1305
时光说笑
时光说笑 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:13

    Finally found the issue:

    Enzyme mount() by default will do full DOM rendering but not insert the rendered component into current document (JSDom). That's why jQuery cannot find any element in current document

    To do full DOM rendering AND attach to current document:

    mount(, { attachTo: document.getElementById('app') });
    

    Where app is empty div available when jsdom is setup:

    global.document = jsdom('
    ');

提交回复
热议问题