Mocha testing failed due to css in webpack Mocha testing failed due to css in webpack reactjs reactjs

Mocha testing failed due to css in webpack


There is a babel/register style hook to ignore style imports:

https://www.npmjs.com/package/ignore-styles

Install it:

npm install --save-dev ignore-styles

Run tests without styles:

mocha --require ignore-styles


you can use a css compilers run mocha, the compiler js as follow:

css-dnt-compiler.js

function donothing() {  return null;}require.extensions['.css'] = donothing;require.extensions['.less'] = donothing;require.extensions['.scss'] = donothing;// ..etc

and run the mocha command like this:

mocha --compilers js:babel-core/register,css:css-dnt-compiler.js --recursive


My same answer as here, this is what I used to get working on Babel 6

package.json

"scripts": {  "test": "mocha --compilers js:babel-core/register           --require ./tools/testHelper.js 'src/**/*-spec.@(js|jsx)'",

tools/testHelper.js

// Prevent mocha from interpreting CSS @import filesfunction noop() {  return null;}require.extensions['.css'] = noop;

This enables you to have your tests inside your src folder alongside your components. You can add as many extensions as you would like with require.extensions.