Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

With WebPack you can import styles in your code like this: import './PageSpinner.styl'; But when you try to test this code with Mocha, your tests will be crashed with SyntaxError because engine tries to handle styles like JS code.

How can I test code like this with Mocha?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
223 views
Welcome To Ask or Share your Answers For Others

1 Answer

I had the same problem lately and the solution was through Mocha compilers.

create a file, let's call it 'css-null-compiler.js' and it has:

function noop() {
  return null;
}

require.extensions['.styl'] = noop;
// you can add whatever you wanna handle
require.extensions['.scss'] = noop;
require.extensions['.png'] = noop;
// ..etc

when you run mocha from the command line, pass this file as a compiler

mocha /your/test.spec.js --compilers css:css-null-compiler.js

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...