summaryrefslogtreecommitdiff
path: root/reuse/features/steps/reusable.js
blob: f4883c893bce83b3ffd18cf159e29a9cb7dc3440 (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
import { Before, Given, Then } from '@cucumber/cucumber'
import { expect } from 'chai'

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'])
})