-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Discussion] [Support needed] Best way to use jQuery #15
Comments
You just need to plug let jQuery = require('jquery');
console.log('Setting up jsdom for node env');
let cleanDom = require('jsdom-global')();;
let $ = jQuery(window);
global.$ = $; // make availble to other files if necessary
$('body').append('<div class="hi">Hello World!</div>');
console.log($('.hi').text()); |
@webxl How can you make it work with jQuery plugins ? Thank you. |
@lionel-bijaoui The plugin just needs to be required after jQuery is added to the window global. let jQuery = require('jquery');
console.log('Setting up jsdom for node env');
let cleanDom = require('jsdom-global')();;
let $ = jQuery(window);
require('jquery-collapse/src/jquery.collapse.js');
global.$ = $; // make availble to other files if necessary
global.jQueryCollapseSection = window.jQueryCollapseSection;
$('body').append(`<div id="test" data-collapse>
<h2>Section 1</h2>
<p>I'm first</p>
<h2>Section 2</h2>
<p>I'm second/p>
</div>`);
$('#test').collapse(); If the plugin references implicit globals, like jquery-collapse does, then you need to copy it to the node.js |
@webxl Thank you for your help. I think I should give you more context. let jQuery = require("jquery");
let $ = jQuery(window);
require("eonasdan-bootstrap-datetimepicker");
global.$ = $; // make availble to other files if necessary
global.datetimepicker = window.datetimepicker; But it fail the condition. If I change the component condition to Thanks ! |
This code seems to be working:
But it requires to use second
jsdom
instance : I cannot accessjsdom
from 'jsdom-global'Is there antipattern? Is there another way to use jQuery and another libs?
Is there good idea to expose
jsdom
instance fromjsdom-global
?The text was updated successfully, but these errors were encountered: