当我尝试使用react-bootstrap-multiselect
和mocha
测试npm模块enzyme
时,出现以下错误:
if (typeof jQuery.fn.dropdown !=="undefined" return jQuery;
TypeError: Cannot read property 'dropdown' of undefined
\react-bootstrap-multiselect\lib\bootstrap-dropdown
发生此错误。我的代码直到错误点是:
import React from 'react';
import { mount } from 'enzyme';
import { expect } from 'chai';
import jsdom from 'jsdom';
const doc = jsdom.jsdom('<!doctype html><html><body></body></html>')
global.document = doc
global.window = doc.defaultView
global.$ = global.jQuery = require('jquery')(global.window);
import MasterTable from '../components/masterTable';
当我尝试导入MasterTable
时抛出错误。 MasterTable尝试渲染react-bootstrap-multiselect
。
答案 0 :(得分:0)
global.window = doc.defaultView
尝试添加后:
global.navigator = window.navigator