warsawjs / topics-manager

App for choosing subjects and signing up as trainers for workshops
MIT License
10 stars 1 forks source link

TypeError: environment.setup is not a function in React Testing #7

Closed greglobinski closed 6 years ago

greglobinski commented 6 years ago

The test command fails with the error:

FAIL  src\__tests__\App.test.js
  ● Test suite failed to run

    TypeError: environment.setup is not a function

      at node_modules/jest-runner/build/run_test.js:71:23

The problem is described on https://stackoverflow.com/questions/48149004/typeerror-environment-setup-is-not-a-function-in-react-testing

Why did we replace the original the create-react-app's jest setup? When I back to

 "scripts": { 
    ...
    "test": "node scripts/test.js --env=jsdom"
  }

test command works, as it should in --watch mode

kgajowy commented 6 years ago

@greglobinski I am not sure about the creation of the project - @Tuhaj could you please share a few words about it? on my side it is working perfectly clean when using npm run test:watch :(

greglobinski commented 6 years ago

@kgajowy Maybe that's because I'm on Windows. I will investigate it further, just wanted to now first why @Tuhaj changed the default settings of create-react-app, what is the reason.

greglobinski commented 6 years ago

I have found the workaround, I've added jest-cli to devDependncies

 "devDependencies": {
    "jest": "^22.4.3",
    "jest-cli": "^23.1.0",
    ...

and the tests run with 'locally' installed jest and without the error. It would be nice to add it to the repo's package.json, but I have no idea if it would not harm you.

Tuhaj commented 6 years ago

@greglobinski I tried to install jest-cli on my side, but:

npm ERR! code EBADPLATFORM
npm ERR! notsup Unsupported platform for inotify@1.4.2: wanted {"os":"linux","arch":"any"} (current: {"os":"darwin","arch":"x64"})
npm ERR! notsup Valid OS:    linux
npm ERR! notsup Valid Arch:  any
npm ERR! notsup Actual OS:   darwin
npm ERR! notsup Actual Arch: x64

The test script command was used from the standard setting, so I think it's unfortunately platform specific. The command you mentioned, doesn't work on my environment too.

greglobinski commented 6 years ago

@Tuhaj Thank you for the feedback, I pulled out the jest-cli workaround. It was not so great :) But I found different solution. On a daily basis I use yarn, but I gave npm a try. I removed npm_modules and installed everything with npm install instead yarn install and guess what... it works :)