1
0

Add an example that reuses a step definition

This commit is contained in:
2018-12-27 08:47:18 +01:00
parent 0e8f395f7a
commit fe4f62ff1a
6 changed files with 2082 additions and 0 deletions

View File

@ -0,0 +1,5 @@
Feature:
Scenario:
Given a person with name
And a person named Jack
Then the same function is called for two distinct step definitions

View File

@ -0,0 +1,28 @@
import { Before, Given, Then } from 'cucumber'
import { expect } from 'chai'
Before(function () {
this.names = []
})
function step (name) {
this.names.push(name)
}
function decorator (f, ...args) {
if (args.length > 0) {
return function () {
f.call(this, args[0])
}
} else {
return f
}
}
Given('a person with name', decorator(step, 'John'))
Given('a person named {word}', decorator(step))
Then('the same function is called for two distinct step definitions', function () {
expect(this.names).to.have.lengthOf(2)
expect(this.names).to.include.members(['John', 'Jack'])
})