Skip to content
This repository has been archived by the owner on Jan 26, 2019. It is now read-only.

vscode jest not getting env=jsdom? #139

Open
Falieson opened this issue Aug 14, 2017 · 4 comments
Open

vscode jest not getting env=jsdom? #139

Falieson opened this issue Aug 14, 2017 · 4 comments

Comments

@Falieson
Copy link

Falieson commented Aug 14, 2017

Sorry this is kind of specific to my IDE (VSCode) but I hope many of you are using it too.
I really like the Jest VSC extension but I haven't gotten it to work w/ my ejected CRA-typescript app yet.
When I run the jest command from command line it works fine, but the IDE jest runner responds with:

 FAIL  src/routes/App.test.tsx
  ● renders without crashing

    ReferenceError: document is not defined
      
      at Object.<anonymous> (src/routes/App.test.tsx:6:15)
          at Promise (<anonymous>)
      at Promise.resolve.then.el (node_modules/p-map/index.js:42:16)
          at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)


  ✕ renders without crashing (36ms)

I've tried changing my .vscode/settings.json in the project root folder to

{
   "jest.pathToJest": "node_modules/.bin/jest --env=jsdom"
}
@alebrozzoSP
Copy link

@Falieson I use a non-ejected cra-ts in VSCode and it works fine... is it possible that when you run the test command, the --env=jsdom parameter is missing?

@mikepatrick
Copy link

You can tell the VSCode Jest plugin to use jsdom by changing the jest configuration in the project's package.json. After ejecting, package.json contains a "jest": key. Inside it, change

"testEnvironment": "node",

to

"testEnvironment": "jsdom",

@VirtuaBoza
Copy link

A note on @mikepatrick's solution, I had to restart vscode before the fix took effect.

@r3nya
Copy link
Contributor

r3nya commented Oct 2, 2018

Hey @Falieson!
Looks like everything is ok right now, please close this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants