LemonPie
LemonPie

Reputation: 846

Jest test __DEV__ is not defined

Basically my issue is that I get an error message, "__DEV__ is not defined" when I run jest. So I have read stackoverflow and other google posts on this. Some have suggested removing my .babelrc, but I actually need that file. Others have suggested adding

"globals": {
  "__DEV__": true
}

To my package.json. I did that as well. I even deleted my node modules folder and re-installed. What should I do? Odd thing is that it was working before, but not now.

Upvotes: 4

Views: 7520

Answers (4)

Max Kelly
Max Kelly

Reputation: 113

For anyone facing this issue I updated my jest by running in the terminal npm update jest this solved the issue for me.

Upvotes: 0

Jose
Jose

Reputation: 2289

I got this when I was running Detox E2E tests inside of my react native app. Then use to work just fine but then I upgraded my mac OS and xcode and they started throwing Reference error DEV is not defined. Not sure why it was fine before and then broke after that.

My issue was fixed when I removed any code that was being imported from my react native app inside of the detox E2E tests. So the issue was importing any javascript from my app/ folder. I had a simple utility log function that wraps console.log which was the culprit. I did not need to modify any jest configs.

Upvotes: 1

Pascal Nitcheu
Pascal Nitcheu

Reputation: 799

You can create a jest.config.json file in the root of your react-native project and add this globally as such

{
"jest": {
    "globals": {
    "__DEV__": true
    }
 }
}

Upvotes: 5

Andreas Köberle
Andreas Köberle

Reputation: 110922

Just add globals.DEV = true to your test file or set it in globals part of your jest settings

Upvotes: 2

Related Questions