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
  • 98,250
  • 56
  • 262
  • 287
XeroxDucati
  • 5,000
  • 1
  • 34
  • 63
  • 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
  • 98,250
  • 56
  • 262
  • 287