面临错误TS2339:类型'StepDefinitions和挂钩'不存在属性'then'

时间:2019-09-13 11:21:31

标签: visual-studio-code protractor cucumber

面对错误TS2339:类型'StepDefinitions&Hooks'上不存在属性'then'。 当我尝试运行tsc -w

尝试了所有我知道的解决方案,但是没有解决办法。

功能文件:

Feature: Login creation for Amazon AWS

    Scenario: Successful creation of Login
        Given User navigate to Home Page
        When User enter email and other details
        Then Login is created sucessfully

Package.json

{
  "name": "package.json",
  "version": "1.0.0",
  "description": "package",
  "main": "index.js",
  "dependencies": {
    "@types/node": "^12.7.5"
  },
  "scripts": {
    "test": "./node_modules/.bin/cucumber-js -p default"
  },
  "compilerOptions": {
    "target": "es6"
  },
  "devDependencies": {
    "@types/chai": "^4.2.2",
    "@types/cucumber": "^4.0.7",
    "chai": "^4.2.0",
    "cucumber": "^5.1.0",
    "cucumber-pretty": "^1.5.2",
    "cucumber-tsflow": "^3.2.0",
    "exceljs": "^2.0.1",
    "protractor": "^5.4.2",
    "protractor-cucumber-framework": "^6.1.3",
    "ts-node": "^8.3.0",
    "typescript": "^3.6.3",
    "xlsx": "^0.15.1"
  },
  "author": "Bharani",
  "license": "ISC"
}

步骤定义文件:

import { Given, When, Then } from "cucumber"


Given("User navigate to Home Page", function(){


       console.log("hafd");
});
When("User enter email and other details",function(){

  console.log("dfhagsdf");

});
Then("Login is created sucessfully",function(){

  console.log("dhfhd");
});

Package.json:

{
  "name": "package.json",
  "version": "1.0.0",
  "description": "package",
  "main": "index.js",
  "dependencies": {
    "@types/node": "^12.7.5"
  },
  "scripts": {
    "test": "./node_modules/.bin/cucumber-js -p default"
  },
  "compilerOptions": {
    "target": "es6"
  },
  "devDependencies": {
    "@types/chai": "^4.2.2",
    "@types/cucumber": "^4.0.7",
    "chai": "^4.2.0",
    "cucumber": "^5.1.0",
    "cucumber-pretty": "^1.5.2",
    "cucumber-tsflow": "^3.2.0",
    "exceljs": "^2.0.1",
    "protractor": "^5.4.2",
    "protractor-cucumber-framework": "^6.1.3",
    "ts-node": "^8.3.0",
    "typescript": "^3.6.3",
    "xlsx": "^0.15.1"
  },
  "author": "Bharani",
  "license": "ISC"
}

控制台错误:

  

'''[16:44:58]在监视模式下开始编译...

     

POM_TS_CUCUMBER / Featurefile / stepdefinition / Steps.ts:3:32-错误   TS2339:类型“ StepDefinitions”上不存在属性“ then”   钩子。

     

3 defineSupportCode(({{Given,When,then})=> {                                    ~~~~

     

[16:45:04]找到1个错误。监视文件更改。 '''

1 个答案:

答案 0 :(得分:0)

您已在非黄瓜库中的特征文件中编写了“然后”。尝试从黄瓜库再次编写然后声明,然后重试。