Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Webpack's DefinePlugin vars in Jest tests

I'm pretty new in React, coming from Angular. I'm writing some tests for the code that's going to send request to an external endpoint. Obviously, I don't want to hardcode a real host in production code so I thought I could use webpack's DefinePlugin to keep this in a constant.

How to configure Webpack and Jest together to use Webpack's capabilities?

like image 949
Kuba T Avatar asked Dec 18 '17 20:12

Kuba T


1 Answers

It's just like that in your package.json or jest.config.js :

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

If you still have any problems, please check the jest offical docs here:

globals-object

like image 188
Seven Avatar answered Oct 20 '22 22:10

Seven