【问题标题】:Testing React-Bootstrap-Multiselect with Mocha用 Mocha 测试 React-Bootstrap-Multiselect
【发布时间】:2016-11-03 16:00:25
【问题描述】:

当我尝试使用 mochaenzyme 测试 npm 模块 react-bootstrap-multiselect 时,我收到以下错误:

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

【问题讨论】:

    标签: javascript jquery reactjs mocha.js enzyme


    【解决方案1】:

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

    global.navigator = window.navigator
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-24
      • 2016-06-13
      • 1970-01-01
      • 2017-04-07
      • 2017-04-19
      相关资源
      最近更新 更多