5

I'm trying to test a react component, and I seem to be hitting a JSDOM issue.

When I mount my component;

const component = mount(
   <PipelineActions pipelineActions={value} {...actions} />
);

I get an error thrown;

document.body.createTextRange is not a function

I tried setting the dom directly via;

(global as any).document = jsdom.jsdom('');
(global as any).window = document.defaultView;

which had no effect. When I try to console.log(document.body) I get something odd as well;

HTMLBodyElement {}

It seems like the DOM isn't getting built right, but I'm not sure why. Has anyone seen this before?

Andreas Köberle
  • 106,652
  • 57
  • 273
  • 297
XeroxDucati
  • 5,130
  • 2
  • 37
  • 66
  • The fix is here https://stackoverflow.com/questions/21572682/createtextrange-is-not-working-in-chrome/46424247#46424247 – danday74 Sep 26 '17 at 13:00

1 Answers1

0

You can set and mock stuff on the global object:

global.body = {createTextRange: jest.fn()}
Andreas Köberle
  • 106,652
  • 57
  • 273
  • 297