rkit / react-select2-wrapper

Wrapper for Select2
MIT License
163 stars 97 forks source link

Having difficulty using with jest / enzyme #70

Closed aberonni closed 7 years ago

aberonni commented 7 years ago

Hi,

I might be doing this wrong, but I'm having a hard time trying to use this inside jest using enzyme's mount to mount my root component. It seems that the Select2 object is not rendered into the DOM when I mount my root component.

This doesn't happen with other components I'm using so I'm not sure whether I'm doing something wrong or rather it is a limitation of this component.

Any help would be greatly appreciated.

aberonni commented 7 years ago

I found a way of interacting with the underlying jquery instance, it isn't exactly a clean method of doing this but I guess it is something:

const $select = $(component.find('Select2 select').getDOMNode());
$select.select2('open');

I'm leaving this open just in case someone else has a better way of doing this.

CWSites commented 5 years ago

@aberonni how did you integrate the code above with your Jest tests? Did you add it to the setup or was it inside of the component you were trying to mount. Can you post a little more info? I'm running into the same issue.

aberonni commented 5 years ago

@CWSites I believe that code was inside the jest test, but I'm relying on my memory. I don't have access to that codebase anymore, sorry.

CWSites commented 5 years ago

Thanks anyways @aberonni!