使用Mocha测试React-Bootstrap-Multiselect

时间:2016-11-03 16:00:25

标签: javascript jquery reactjs mocha enzyme

当我尝试使用react-bootstrap-multiselectmocha测试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

1 个答案:

答案 0 :(得分:0)

global.window = doc.defaultView尝试添加后:

global.navigator = window.navigator