Mocha will not recognise JSX

前端 未结 1 705
广开言路
广开言路 2020-12-11 16:26

I am trying to update my unit tests by using mocha and enzyme. The code that I am testing is in ES6, using JSX and React.

I have been unable to get mocha to

相关标签:
1条回答
  • 2020-12-11 17:03

    This has been a very common problem for users of Babel 6, which on its own (babel-core) doesn't do anything. It requires that transforms / plugins are fed to it during transpilation.

    Babel offers bundles of common plugins as presets. Common for React projects are babel-preset-2015, babel-preset-react and babel-preset-stage-0. After npm installing them, add a .babelrc config file that looks something like this:

    {
      "presets": ["react", "es2015", "stage-0"]
    }
    

    For mocha with gulp checkout this stack gulp-mocha how to pass the compilers flag?.

    And read here about setting up Babel 6 generally https://babeljs.io/blog/2015/10/31/setting-up-babel-6

    0 讨论(0)
提交回复
热议问题