Skip to content
This repository was archived by the owner on Dec 16, 2023. It is now read-only.

How to access jsdom instance? #1098

Closed
deyceg opened this issue Nov 21, 2016 · 2 comments
Closed

How to access jsdom instance? #1098

deyceg opened this issue Nov 21, 2016 · 2 comments

Comments

@deyceg
Copy link

deyceg commented Nov 21, 2016

Hey,

Is there a way to access the underlying jsdom instance? I'm trying to bridge cucumber js/zombie/enzyme.

I'm not entirely sure if zombie/enzyme would use the same instance of jsdom through normal require mechanics as theres some very specific setup for enzyme/jsdom:

/* setup.js */

var jsdom = require('jsdom').jsdom;

global.document = jsdom('');
global.window = document.defaultView;
Object.keys(document.defaultView).forEach((property) => {
  if (typeof global[property] === 'undefined') {
    global[property] = document.defaultView[property];
  }
});

global.navigator = {
  userAgent: 'node.js'
};

Whilst not related to zombie, im trying to mount a react/redux app into jsdom to perform some BDD style tests using .feature files (gherkin syntax).

Not got alot of experience with Zombie so I may be able to cut out enzyme completely!

@mdlavin
Copy link
Collaborator

mdlavin commented Nov 22, 2016

It would be a bit of a hack, but you could try require('zombie/dom') and see if that gives you the access you want.

@deyceg
Copy link
Author

deyceg commented Nov 22, 2016

@mdlavin I went with this instead and it appears to be working:

this.browser.visit('http://localhost', function(){
      var exposedProperties = ['window', 'navigator', 'document'];

      global.document = this.browser.document;
      global.window = this.browser.document.defaultView
      Object.keys(document.defaultView).forEach((property) => {
        if (typeof global[property] === 'undefined') {
          exposedProperties.push(property);
          global[property] = document.defaultView[property];
        }
      });

     // Able to use enzyme now
})

@mdlavin mdlavin closed this as completed Nov 23, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants