rkit / react-select2-wrapper

Wrapper for Select2
MIT License
163 stars 97 forks source link

TypeError: this.el.select2 is not a function #83

Open scottybollinger opened 6 years ago

scottybollinger commented 6 years ago

https://github.com/rkit/react-select2-wrapper/issues/36 is still happening with the latest version 1.0.4-beta.

TypeError: this.el.select2 is not a function when mounting a component in a Jest unit test.

Dcuevac93 commented 6 years ago

I'm having the same problem. This is what i have in my package.json "react-select2-wrapper": "^1.0.4-beta5". Any solution?

CWSites commented 5 years ago

I'm also having the same issue with the latest 1.0.4-beta6 when mounting a component in a Jest unit test. I'm using Enzyme as well.

TypeError: this.el.select2 is not a function
        at Select2.initSelect2 (node_modules/react-select2-wrapper/lib/components/Select2.js:94:15)
        at Select2.componentDidMount (node_modules/react-select2-wrapper/lib/components/Select2.js:64:12)
agungyuliaji commented 5 years ago

i only got this error when using jest + enzyme

CWSites commented 5 years ago

@rkit any help you could provide here? I've spent a week trying to figure this out, building mocks for select2, importing jquery in different places, etc. This is the only issue preventing me from using your library.

agungyuliaji commented 5 years ago

solved by adding this

global.$ = require('jquery')
global.$.fn.select2 = require('select2')

on jest setup file

CWSites commented 5 years ago

Thank you @agungyuliaji, you're a lifesaver!

agungyuliaji commented 5 years ago

Glad to hear that! anyway it's jest problem. the issue is not related with this plugin.

syedn commented 5 years ago

the issue was resolved for me when I added global.$ = require('jquery') global.$.fn.select2 = require('select2') to app.js

Thanks @agungyuliaji

CWSites commented 5 years ago

@rkit this can be closed.