-
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
Can't access the JSDOM API #26
Comments
+1 |
This is an important issue, because |
Will allow to access jsdom API (rstacruz#26).
I'd have preferred to leave this in place until I've finished building the replacement. Alas, use of window.alert() didn't play well with the test environment since jsdom-global doesn't expose enough of jsdom for me to override window.alert nor prevent its absence from cancelling the test. rstacruz/jsdom-global#26
I think this manual script from the Enzyme docs more-or-less deprecates this package and solves this issue. Quoting for convenience: /* setup.js */
const { JSDOM } = require('jsdom');
const jsdom = new JSDOM('<!doctype html><html><body></body></html>');
const { window } = jsdom;
function copyProps(src, target) {
Object.defineProperties(target, {
...Object.getOwnPropertyDescriptors(src),
...Object.getOwnPropertyDescriptors(target),
});
}
global.window = window;
global.document = window.document;
global.navigator = {
userAgent: 'node.js',
};
global.requestAnimationFrame = function (callback) {
return setTimeout(callback, 0);
};
global.cancelAnimationFrame = function (id) {
clearTimeout(id);
};
copyProps(window, global); You can export the instance, make it global, whatever works for your use case. |
As of version 3, there's no way to access the JSDOM api (here) directly. Some functions such as
reconfigure
are important.How do you think we can expose a reference to it? Please guide me and I'll be happy to make a PR.
Thanks!
The text was updated successfully, but these errors were encountered: