I have this react + rails app that I use axios to communicate with the backend with, naturally I have to set up the CSRF token like this
export default axios.create({
headers:{
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').getAttribute('content')
}
})
But this screws up with my mocha test as document.querySelector doesn't exist in that environment; Is there anyway that I can specify like when mocha is running this file, it will just export axios, anything else, it's that axios.create(...)?
Like so:
export default TEST ? axios : axios.create(...)
Here is the scripts section of the package.json
"scripts": {
"test": "NODE_ENV=test mocha './app/**/*.spec.js' --compilers js:babel-core/register --require testSetup.js",
"test:watch": "npm test -- --watch",
"start": "node server.js"
},
I am still new to mocha testing, and I don't have any mocha specific code in the webpack.config.js file.
Thanks a million!