如何使用Jest测试js中的箭头功能?

时间:2018-12-20 13:24:53

标签: reactjs npm jestjs babel yarnpkg

你能帮我吗?我不知道该怎么办,我的问题是:

    var meterData = MeterTable(startDateTime, endDateTime);
    var levelData = LevelTable(startDateTime, endDateTime);

      var dataTable = new DataTable();
                dataTable.Columns.Add("Meter", typeof(string));
                dataTable.Columns.Add("Volume", typeof(int));
                dataTable.Columns.Add("OpeningBalance", typeof(int));
                dataTable.Columns.Add("IN", typeof(int));
                dataTable.Columns.Add("Transfer", typeof(int));
                dataTable.Columns.Add("OUT", typeof(int));
                dataTable.Columns.Add("ClosingBalance", typeof(int));
   // how Onward i have not any idea ?

我对它完全陌生,所以请原谅我的愚蠢。我尝试了多种方法来解决此问题,但是没有人帮助我,因此希望您能为我提供帮助。 顺便说一句,我正在使用:

  • npm 6.4.1
  • 节点8.14.0
  • 笑话23.6.0
  • babel 6.26.0

我的测试代码在这里:

C:/Users/../Coung.js: Unexpected token (511:13)

  Jest encountered an unexpected token
  This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
  By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
  Here's what you can do:
   • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
   • If you need a custom transformation specify a "transform" option in your config.
   • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
  You'll find more details and examples of these config options in the docs:
  https://jestjs.io/docs/en/configuration.html
  Details:
    509 | 
    510 | 
  > 511 |   toggleMenu = (tab) => {
        |              ^
    512 |     const painter = this.state.painter;
    513 |     let showThreeD = false;
    514 |     let disabledShowThreeD = true;

先谢谢了。

1 个答案:

答案 0 :(得分:0)

从您的package.json来看,您正在使用@babel/core。我相信Jest目前与babel 7有关。尝试添加babel-core桥包,看看它是否可以正常工作。

npm install babel-core@^7.0.0-bridge.0 --save-dev