skratchdot / react-bootstrap-multiselect

A multiselect component for react (with bootstrap). This is a react port of bootstrap-multiselect.
http://projects.skratchdot.com/react-bootstrap-multiselect/
Other
119 stars 62 forks source link

Mocha Testing #59

Open ghost opened 7 years ago

ghost commented 7 years ago

When I try to test the npm modulereact-bootstrap-multiselect with mocha and enzyme, I get the following error:

if (typeof jQuery.fn.dropdown !=="undefined" return jQuery;
TypeError: Cannot read property 'dropdown' of undefined
this error happens in \react-bootstrap-multiselect\lib\bootstrap-dropdown. My code up to the point of error is:

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';

where the error is thrown when I try to import MasterTable. MasterTable tries to render the react-bootstrap-multiselect.

Link to StackOverflow post http://stackoverflow.com/questions/40406149/testing-react-bootstrap-multiselect-with-mocha

skratchdot commented 7 years ago

Thank you! I will try to fix this when I get a bit of time this weekend.

ghost commented 7 years ago

Please let me know when you have it fixed. The fix you sent me doesn't seem to work.

Thanks.

iggi- commented 7 years ago

I have the same error. The odd part is that it worked for a while and then seems to have failed. I'm unsure why.

otanim commented 7 years ago

@lawrencetvo, @iggi- instead of define the react-bootstrap-multiselect package in this way:

import Multiselect from 'react-bootstrap-multiselect'

try

let Multiselect;
if (typeof(window) !== 'undefined') {
  Multiselect = require('react-bootstrap-multiselect');
}

idk, seems this repository no longer maintained, I probably will use this alternative: https://jedwatson.github.io/react-select/

skratchdot commented 7 years ago

I should definitely keep a list of alternatives in the readme. I keep meaning to update this repo one weekend, but have been so busy lately. There are definitely some good pure react libs out there (this one is just a wrapper around an existing jQuery library). I will try to update this lib soon though (and add some unit tests).

NilapuAnusha commented 6 years ago

When I run test cases got error from react-bootstrap-multiselect. I am using enzyme, mocha and chai.

`ReferenceError: jQuery is not defined at Object../node_modules/bootstrap/js/transition.js (/home/anusha/Skua/cs-connect/05-12-2017/node_modules/bootstrap/js/transition.js:59:1)
at __webpack_require__ (/home/anusha/Skua/cs-connect/05-12-2017/webpack/bootstrap 3ba9ca30786fab8785a6:669:1)
at fn (/home/anusha/Skua/cs-connect/05-12-2017/webpack/bootstrap 3ba9ca30786fab8785a6:87:1)
at Object../node_modules/bootstrap/dist/js/npm.js (/home/anusha/Skua/cs-connect/05-12-2017/node_modules/bootstrap/dist/js/npm.js:2:1)
at __webpack_require__ (/home/anusha/Skua/cs-connect/05-12-2017/webpack/bootstrap 3ba9ca30786fab8785a6:669:1)
at fn (/home/anusha/Skua/cs-connect/05-12-2017/webpack/bootstrap 3ba9ca30786fab8785a6:87:1)
at Object../node_modules/react-bootstrap-multiselect/dist/index.js (/home/anusha/Skua/cs-connect/05-12-2017/node_modules/react-bootstrap-multiselect/dist/index.js:21:1)
at __webpack_require__ (/home/anusha/Skua/cs-connect/05-12-2017/webpack/bootstrap 3ba9ca30786fab8785a6:669:1)
at fn (/home/anusha/Skua/cs-connect/05-12-2017/webpack/bootstrap 3ba9ca30786fab8785a6:87:1)
at Object../src/components/search-form-panel.js (/home/anusha/Skua/cs-connect/05-12-2017/src/components/search-form-panel.js:1:1)
at __webpack_require__ (/home/anusha/Skua/cs-connect/05-12-2017/webpack/bootstrap 3ba9ca30786fab8785a6:669:1)
at fn (/home/anusha/Skua/cs-connect/05-12-2017/webpack/bootstrap 3ba9ca30786fab8785a6:87:1)
at Object../src/components/search-panel.js (/home/anusha/Skua/cs-connect/05-12-2017/src/components/search-panel.js:1:1)
at __webpack_require__ (/home/anusha/Skua/cs-connect/05-12-2017/webpack/bootstrap 3ba9ca30786fab8785a6:669:1)
at fn (/home/anusha/Skua/cs-connect/05-12-2017/webpack/bootstrap 3ba9ca30786fab8785a6:87:1)
at Object../src/containers/search/search-panel-container.js (/home/anusha/Skua/cs-connect/05-12-2017/src/containers/search/search-panel-container.js:1:1)
at __webpack_require__ (/home/anusha/Skua/cs-connect/05-12-2017/webpack/bootstrap 3ba9ca30786fab8785a6:669:1)
at fn (/home/anusha/Skua/cs-connect/05-12-2017/webpack/bootstrap 3ba9ca30786fab8785a6:87:1)
at Object../test/containers/search/search-panel-container.test.js (/home/anusha/Skua/cs-connect/05-12-2017/test/containers/search/search-panel-container.test.js:1:1)
at __webpack_require__ (/home/anusha/Skua/cs-connect/05-12-2017/webpack/bootstrap 3ba9ca30786fab8785a6:669:1)
at fn (/home/anusha/Skua/cs-connect/05-12-2017/webpack/bootstrap 3ba9ca30786fab8785a6:87:1)
at run (/home/anusha/Skua/cs-connect/05-12-2017/node_modules/mocha-webpack/lib/entry.js:3:1)
at Array.forEach (<anonymous>)
at Object.<anonymous> (/home/anusha/Skua/cs-connect/05-12-2017/node_modules/mocha-webpack/lib/entry.js:10:1)
at Object../node_modules/mocha-webpack/lib/entry.js (/home/anusha/Skua/cs-connect/05-12-2017/.tmp/mocha-webpack/1513599486373/bundle.js:25706:30)
at __webpack_require__ (/home/anusha/Skua/cs-connect/05-12-2017/webpack/bootstrap 3ba9ca30786fab8785a6:669:1)
at /home/anusha/Skua/cs-connect/05-12-2017/webpack/bootstrap 3ba9ca30786fab8785a6:715:1
at Object.<anonymous> (/home/anusha/Skua/cs-connect/05-12-2017/.tmp/mocha-webpack/1513599486373/bundle.js:719:10)
at Module._compile (module.js:635:30)
at Object._module2.default._extensions.(anonymous function) [as .js] (/home/anusha/Skua/cs-connect/05-12-2017/node_modules/mocha-webpack/lib/util/registerRequireHook.js:147:12)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at /home/anusha/Skua/cs-connect/05-12-2017/node_modules/mocha/lib/mocha.js:231:27
at Array.forEach (<anonymous>)
at Mocha.loadFiles (/home/anusha/Skua/cs-connect/05-12-2017/node_modules/mocha/lib/mocha.js:228:14)
at Mocha.run (/home/anusha/Skua/cs-connect/05-12-2017/node_modules/mocha/lib/mocha.js:514:10)
at runMocha (/home/anusha/Skua/cs-connect/05-12-2017/node_modules/mocha-webpack/lib/runner/TestRunner.js:249:35)
at /home/anusha/Skua/cs-connect/05-12-2017/node_modules/mocha-webpack/lib/runner/TestRunner.js:305:13
at Compiler.<anonymous> (/home/anusha/Skua/cs-connect/05-12-2017/node_modules/mocha-webpack/lib/webpack/compiler/registerReadyCallback.js:26:7)
at Compiler.applyPlugins (/home/anusha/Skua/cs-connect/05-12-2017/node_modules/tapable/lib/Tapable.js:61:14)
at Watching._done (/home/anusha/Skua/cs-connect/05-12-2017/node_modules/webpack/lib/Compiler.js:104:17)
at compiler.emitRecords.err (/home/anusha/Skua/cs-connect/05-12-2017/node_modules/webpack/lib/Compiler.js:78:19)
at Compiler.emitRecords (/home/anusha/Skua/cs-connect/05-12-2017/node_modules/webpack/lib/Compiler.js:375:38)
at compiler.emitAssets.err (/home/anusha/Skua/cs-connect/05-12-2017/node_modules/webpack/lib/Compiler.js:61:20)
at applyPluginsAsyncSeries1.err (/home/anusha/Skua/cs-connect/05-12-2017/node_modules/webpack/lib/Compiler.js:368:12)
at next (/home/anusha/Skua/cs-connect/05-12-2017/node_modules/tapable/lib/Tapable.js:218:11)
at Compiler.compiler.plugin (/home/anusha/Skua/cs-connect/05-12-2017/node_modules/webpack/lib/performance/SizeLimitsPlugin.js:99:4)
at Compiler.applyPluginsAsyncSeries1 (/home/anusha/Skua/cs-connect/05-12-2017/node_modules/tapable/lib/Tapable.js:222:13)
at Compiler.afterEmit (/home/anusha/Skua/cs-connect/05-12-2017/node_modules/webpack/lib/Compiler.js:365:9)
at require.forEach.err (/home/anusha/Skua/cs-connect/05-12-2017/node_modules/webpack/lib/Compiler.js:360:15)
at /home/anusha/Skua/cs-connect/05-12-2017/node_modules/async/dist/async.js:473:16
at iteratorCallback (/home/anusha/Skua/cs-connect/05-12-2017/node_modules/async/dist/async.js:1050:13)
at /home/anusha/Skua/cs-connect/05-12-2017/node_modules/async/dist/async.js:958:16
at Compiler.writeOut (/home/anusha/Skua/cs-connect/05-12-2017/node_modules/webpack/lib/Compiler.js:344:14)
at Immediate.<anonymous> (/home/anusha/Skua/cs-connect/05-12-2017/node_modules/memory-fs/lib/MemoryFileSystem.js:288:4)
at runCallback (timers.js:789:20)
at tryOnImmediate (timers.js:751:5)
at processImmediate [as _immediateCallback] (timers.js:722:5)

`

NilapuAnusha commented 6 years ago

Issue is fixed when I add global.$ = global.jQuery = require('jquery')

NilapuAnusha commented 6 years ago

@lawrencetvo Could you please look into #80?