Open WickyNilliams opened 7 years ago
Have you tried running "npm run devtool" in a clone of this repo? I can access window and other methods fine there.
I think you misunderstand what I'm asking. This package works great in a node environment, no problems there.
I want to find out how this package fixes the issue of debugging with jest, so that I can port the fixes to a jsdom environment.
Hope that clear it up
Oh wait, maybe you do understand. When I use this to run tests for react code, it complains about not being able to find document
etc
hey nick! What I mean to say is that since often times when this module doesn't work for people is because they haven't setup something right. Can you please checkout the master branch of this repo, then run npm install and npm run devtool because document does work for me!
I believe that when you run the tests in devtool, it uses its own DOM, which is why those tests pass. This can be proven by logging the userAgent to console, or calling toString on a DOM method, which yields function() { [ native code ] }
(i.e. not jsdom).
If i run the tests directly with jest:
yarn jest
Then they also pass, because jest defaults to jsdom. However if i tell jest to use this environment:
yarn jest -- --env ./index.js
then I get the following:
FAIL debug-test/__tests__/testFileTest.js
● Test › Can debug
ReferenceError: document is not defined
at Object.setSomethingInWindow (debug-test/testFile.js:3:26)
at Object.it (debug-test/__tests__/testFileTest.js:5:18)
Test
✕ Can debug (2ms)
So I think that this environment config doesn't work with jsdom
@WickyNilliams I see! sorry for confusion earlier. I think I will need to create a jest-environment-jsdom-fixed for this issue :) Because this package was intended for node environment debugging by @develar
@WickyNilliams Do you mind trying this out? https://www.npmjs.com/package/jest-environment-jsdom-debug
No worries.
Tried it. It works on the whole, but fails when I have a test using File
constructor. That tests works when using regular jsdom environment
This works great for debugging tests in node, but doesn't work for debugging front-end tests that require jsdom.
I'd like to create a similar fixed jest environment for jsdom, but I'm not sure which parts of this package are important. I was wondering if you could explain how this package fixes the jest issues, and how I might port this to a jsdom environment.