summaryrefslogtreecommitdiff
path: root/reuse/features/steps/reusable.js
blob: 07ac8c5801200c71776a6eb0c9bf0b522497891c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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'])
})