rstacruz / jsdom-global

Enable DOM in Node.js
477 stars 38 forks source link

Set `pretendToBeVisual` to true? #38

Open mAAdhaTTah opened 6 years ago

mAAdhaTTah commented 6 years ago

Using jsdom-global w/ some mocha tests and I've been polyfilling rAF up to this point. jsdom 11 now ships with requestAnimationFrame, but it has to be enabled. Is this something jsdom-global would be interested in doing by default?

andreasvirkus commented 6 years ago

Even if jsdom-global won't add this as a default, I'd say some documentation would be helpful. Like how to enable pretendToBeVisual when initiating jsdom-global. From jsdom docs, I see that we need to construct a new window object:

const window = (new JSDOM(``, { pretendToBeVisual: true })).window;

But I'm not 100% where to do this? My global unit tests setup currently looks like:

require('jsdom-global')();

// Popper doesn't work in JSDOM
class MockedPopper {
  constructor() {
    this.placements = global.Popper.placements;
    return {
      destroy: () => {},
      scheduleUpdate: () => {},
    };
  }
}

global.Popper = MockedPopper;

Sorry to hijack 😶

mstrutt commented 6 years ago

I had a look through the source of index.js, seems you can pass in jsdom options to jsdom-global. This did the trick for me:

require('jsdom-global')(undefined, { pretendToBeVisual: true });
i-am-the-slime commented 2 years ago

How do you do this with import rather than require?