summaryrefslogtreecommitdiff
path: root/type-parser/features/steps/custom-type.js
blob: 28f44aa71c778ce6f0fcfb967ec004c219cf4d2e (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { Before, Given, When, Then, defineParameterType } from '@cucumber/cucumber'
import { expect } from 'chai'

defineParameterType({
  name: 'tobe',
  regexp: [
    /is/,
    /is not/
  ],
  transformer: x => x === 'is'
})

When('I interpret "to be" as a type', function () {
})
       
Then('true {tobe} true', function (predicate) {
  expect(predicate).to.be.true
})

Then('false {tobe} true', function (predicate) {
  expect(predicate).to.be.false
})

defineParameterType({
  name: 'date',
  regexp: /\d{2}\.\d{2}\.\d{4}/
})

When('a date {date} is given', function (dateString) {
  const parts = dateString.split('.').reverse()
  this.date = new Date(...parts)
})

Then('it gets converted to a Date object', function () {
  expect(this.date).to.be.an.instanceof(Date)
})

Before(function () {
  this.count = 0
})

Given(/(a regular expression|it) matches (this|that) pattern/, function (_x, _y) {
  ++this.count
})

Then('the step definition should be called twice', function () {
  expect(this.count).to.equal(2)
})