我一直想弄清楚为什么为什么cucumber-tsflow
的一些步骤定义不能被黄瓜识别,但是裸露的cucumber
包定义仍然可以正常工作。有人遇到过这个问题吗?任何帮助将不胜感激!
我的回购结构如下:
root/
- features/sample.feature
- steps/steps.ts
在sample.feature里面,我有:
Feature: Simple maths
In order to do maths
As a developer
I want to increment variables
Scenario: easy maths
Given a variable set to 1
When I increment the variable by 1
Then the variable should contain 2
不起作用代码段(steps.ts):
import assert = require('assert')
import { binding, given, then, when } from 'cucumber-tsflow'
@binding()
class MySteps {
private a: number
@given('/a variable set to "([^"]*)"/')
public aVariableSetTo(searchValue: string): void {
this.a = Number(searchValue)
}
@when('/I increment the variable by "([^"]*)"/')
public incrementTheVariableBy(increment: string): void {
this.a = this.a + Number(increment)
}
@then('/the variable should contain "([^"]*)"/')
public theVariableShouldContain(expected: string): void {
assert.equal(this.a, Number(expected))
}
}
export = MySteps
工作中代码段(steps.ts):
const { Given, When, Then } = require('cucumber')
var assert = require('assert')
let a
Given('a variable set to {int}', function(number) {
a = number
})
When('I increment the variable by {int}', function(number) {
a = a + number
})
Then('the variable should contain {int}', function(number) {
assert.equal(a, number)
})
我用来运行测试的命令是:
./node_modules/.bin/cucumber-js src/test/features/ --require src/test/steps/*.ts --require-module ts-node/register
我的软件包版本为:
"cucumber": "^5.0.2",
"cucumber-tsflow": "^3.1.0",
"ts-node": "^7.0.1",
"typescript": "~3.1.6"
我尝试过(但失败了)以修复不工作版本的各种措施: