-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathparameter_types.feature
138 lines (120 loc) · 3.81 KB
/
parameter_types.feature
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
Feature: Parameter types
Users can define their own parameter types to be used in Cucumber expressions.
Custom parameter types can be used to match certain patterns, and optionally to
transform the matched value into a custom type.
Background:
Given a file named "features/particular_steps.feature" with:
"""
Feature: a feature
Scenario: a scenario
Given a particular step
"""
Given a file named "features/step_definitions/my_steps.js" with:
"""
const assert = require('assert')
const {Given} = require('@cucumber/cucumber')
Given('a {param} step', function(param) {
assert.equal(param, 'PARTICULAR')
})
"""
Scenario: delegate transform to world
Given a file named "features/support/transforms.js" with:
"""
const {setWorldConstructor, defineParameterType} = require('@cucumber/cucumber')
defineParameterType({
regexp: /particular/,
transformer(s) {
return this.upcase(s)
},
name: 'param'
})
class MyWorld {
upcase(s) {
return s.toUpperCase()
}
}
setWorldConstructor(MyWorld)
"""
When I run cucumber-js
Then scenario "a scenario" step "Given a particular step" has status "passed"
Scenario: sync transform (success)
Given a file named "features/support/transforms.js" with:
"""
const {defineParameterType} = require('@cucumber/cucumber')
defineParameterType({
regexp: /particular/,
transformer: s => s.toUpperCase(),
name: 'param'
})
"""
When I run cucumber-js
Then scenario "a scenario" step "Given a particular step" has status "passed"
Scenario: sync transform (error)
Given a file named "features/support/transforms.js" with:
"""
const {defineParameterType} = require('@cucumber/cucumber')
defineParameterType({
regexp: /particular/,
transformer: s => {
throw new Error('transform error')
},
name: 'param'
})
"""
When I run cucumber-js
Then it fails
And scenario "a scenario" step "Given a particular step" failed with:
"""
transform error
"""
Scenario: no transform
Given a file named "features/support/transforms.js" with:
"""
const {defineParameterType} = require('@cucumber/cucumber')
defineParameterType({
regexp: /particular/,
name: 'param'
})
"""
When I run cucumber-js
Then it fails
And scenario "a scenario" step "Given a particular step" failed with:
"""
AssertionError
"""
Scenario: async transform (success)
Given a file named "features/step_definitions/particular_steps.js" with:
"""
const {defineParameterType} = require('@cucumber/cucumber')
defineParameterType({
regexp: /particular/,
transformer: s => Promise.resolve(s.toUpperCase()),
name: 'param'
})
"""
When I run cucumber-js
Then scenario "a scenario" step "Given a particular step" has status "passed"
Scenario: async transform (error)
Given a file named "features/step_definitions/particular_steps.js" with:
"""
const {defineParameterType} = require('@cucumber/cucumber')
defineParameterType({
regexp: /particular/,
transformer: s => Promise.reject(new Error('transform error')),
name: 'param'
})
"""
When I run cucumber-js
Then it fails
And scenario "a scenario" step "Given a particular step" failed with:
"""
transform error
"""
Scenario: undefined parameter type
When I run cucumber-js with `-f progress`
Then it fails
And the output contains the text:
"""
Undefined parameter types:
- "param" e.g. `a {param} step`
"""