【问题标题】:cucumberjs unexpected token with imported files that has arrow functions带有箭头功能的导入文件的 cucumberjs 意外令牌
【发布时间】:2020-03-22 02:14:44
【问题描述】:

我有一个类,我正在尝试用 cucumberjs 进行测试。当我从功能中导入类时,它会在我运行 cucumberjs 时给我以下信息

我执行的命令

./node_modules/.bin/cucumber-js ./tests/features

我得到的错误

getAll = () => this.data;
           ^

SyntaxError: Unexpected token =
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
:

:

:

文件

// TestApi.js
class TestApi {
    constructor(){
        this.data = ['teststuff', 'teststuff2']
    }

    getAll = () => this.data;
}



//test.feature

const { Before, Given, When, Then } = require('cucumber') 
const { TestApi } = require('../../../api/TestApi.js');
const { TestDomain } = require('../../../domain/domain.js');

【问题讨论】:

    标签: javascript cucumber cucumberjs


    【解决方案1】:

    问题不在于 CucumberJS,而在于您机器上的 NodeJS 版本。您可以通过在终端中运行 node -v 命令来检查当前版本。如果您的版本早于NodeJS website 上当前列出的 LTS 版本,请按照安装说明进行操作。

    在线示例:https://testjam.io/?p=ZVpoJT4AkNHy9PTxeure

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-23
      • 2016-06-18
      • 1970-01-01
      • 2017-11-08
      • 2019-03-21
      • 2020-03-16
      相关资源
      最近更新 更多