3

I am using DefinedPlugin() to set global staging variables inside webpack.config.js.

This is working and I am able to retrieve these variables in my app files.

The issue I have is when I run the unit test with Mocha it throws an error

ReferenceError: __A_VARIABLE__ is not defined

This is correct because Webpack uses string replace to replace the variable key string with the one in the config file.

My questions is how do we use mocha and unit test variables set in DefinePlugin when testing the /src files

webpack.config.js

...

plugins: [
 new webpack.DefinePlugin({
  __A_VARIABLE__: JSON.stringify('some string')
 })
]

...

/src/some-file.js

 somefunction() {
   somelogic using __A_VARIABLE__
 }
user742736
  • 2,629
  • 5
  • 30
  • 40

0 Answers0