-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathfailing_steps.feature
145 lines (128 loc) · 4.15 KB
/
failing_steps.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
139
140
141
142
143
144
145
Feature: Failing steps
Background:
Given a file named "features/fail.feature" with:
"""
Feature: a feature
Scenario: a scenario
Given a failing step
"""
Scenario: too few arguments
Given a file named "features/step_definitions/failing_steps.js" with:
"""
const {When} = require('@cucumber/cucumber')
When(/^a (.*) step$/, function() {})
"""
When I run cucumber-js
Then it fails
And scenario "a scenario" step "Given a failing step" failed with:
"""
function has 0 arguments, should have 1 (if synchronous or returning a promise) or 2 (if accepting a callback)
"""
Scenario: too many arguments
Given a file named "features/step_definitions/failing_steps.js" with:
"""
const {When} = require('@cucumber/cucumber')
When(/^a failing step$/, function(arg1, arg2) {})
"""
When I run cucumber-js
Then it fails
And scenario "a scenario" step "Given a failing step" failed with:
"""
function has 2 arguments, should have 0 (if synchronous or returning a promise) or 1 (if accepting a callback)
"""
Scenario: synchronous - throws
Given a file named "features/step_definitions/failing_steps.js" with:
"""
const {When} = require('@cucumber/cucumber')
When(/^a failing step$/, function() {
throw new Error('my error');
})
"""
When I run cucumber-js
Then it fails
And scenario "a scenario" step "Given a failing step" failed with:
"""
my error
"""
@spawn
Scenario: asynchronous - throws
Given a file named "features/step_definitions/failing_steps.js" with:
"""
const {When} = require('@cucumber/cucumber')
When(/^a failing step$/, function(callback) {
setTimeout(function() {
throw new Error('the expected error in an async step')
})
})
"""
When I run cucumber-js
Then it fails
And scenario "a scenario" step "Given a failing step" failed with:
"""
the expected error in an async step
"""
Scenario: asynchronous - passing error as first argument to the callback
Given a file named "features/step_definitions/failing_steps.js" with:
"""
const {When} = require('@cucumber/cucumber')
When(/^a failing step$/, function(callback) {
setTimeout(function() {
callback(new Error('my error'))
})
})
"""
When I run cucumber-js
Then it fails
And scenario "a scenario" step "Given a failing step" failed with:
"""
my error
"""
Scenario: asynchronous - using a callback and returning a promise
Given a file named "features/step_definitions/failing_steps.js" with:
"""
const {When} = require('@cucumber/cucumber')
When(/^a failing step$/, function(callback) {
return Promise.resolve()
})
"""
When I run cucumber-js
Then it fails
And scenario "a scenario" step "Given a failing step" failed with:
"""
function uses multiple asynchronous interfaces: callback and promise
to use the callback interface: do not return a promise
to use the promise interface: remove the last argument to the function
"""
@spawn
Scenario: promise - throws
Given a file named "features/step_definitions/failing_steps.js" with:
"""
const {When} = require('@cucumber/cucumber')
When(/^a failing step$/, function() {
return new Promise(function() {
setTimeout(function() {
throw new Error('my error')
})
})
})
"""
When I run cucumber-js
Then it fails
And scenario "a scenario" step "Given a failing step" failed with:
"""
my error
"""
Scenario: promise - rejects
Given a file named "features/step_definitions/failing_steps.js" with:
"""
const {When} = require('@cucumber/cucumber')
When(/^a failing step$/, function() {
return Promise.reject(new Error('my error'))
})
"""
When I run cucumber-js
Then it fails
And scenario "a scenario" step "Given a failing step" failed with:
"""
my error
"""