Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Unable to mock document.createRange with setupTests.js #54

Closed
RusinovAnton opened this issue Sep 27, 2018 · 6 comments
Closed

Unable to mock document.createRange with setupTests.js #54

RusinovAnton opened this issue Sep 27, 2018 · 6 comments

Comments

@RusinovAnton
Copy link

My tests are failing in CI because of following error.


TypeError: document.createRange is not a function

    at findCommonOffsetParent (/app/node_modules/popper.js/dist/umd/popper.js:259:24)

    at getReferenceOffsets (/app/node_modules/popper.js/dist/umd/popper.js:744:83)

    at Popper.update (/app/node_modules/popper.js/dist/umd/popper.js:918:28)

    at Popper.update$$1 (/app/node_modules/popper.js/dist/umd/popper.js:2466:21)

    at /app/node_modules/popper.js/dist/umd/popper.js:51:7

    at <anonymous>

 DEBUG [7c086cee] 	

I've tried to mock this function globally by adding src/setupTests.js like documentation of CRA suggests:
https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#initializing-test-environment

But that wasn't efficient - they're still failing

@papermana
Copy link

Hm, what does your src/setupTests.js look like?

There was a discussion about this problem in the Popper repo and someone had a solution that supposedly works.

@RusinovAnton
Copy link
Author

I did take that snippet excluding enzyme adapter since I do not use enzyme at all

@RusinovAnton
Copy link
Author

RusinovAnton commented Sep 28, 2018

https://github.com/NodusMedical/nodus-frontend/pull/65/files

Nevermind jest config in package.json part. It doesn't make any effect

@RusinovAnton
Copy link
Author

I've tried to make test of setupTests.js and added next code there

document.RAWR = 'test';

and then tried to access it in one of my tests like

typeof document.RAWR

And it said that RAWR is undefined

@papermana
Copy link

There's a typo there.

"setupFiles": ["./setup.test.js"]

But the actual file is setupTests.js.

@RusinovAnton
Copy link
Author

The issue was with invalid Circle CI configuration.
I was using "prebuild" script to run "yarn test" command.
Now changed it for Circle CI job and problem is gone.

Sorry for false issue

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