-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathhooks.feature
96 lines (81 loc) · 2.42 KB
/
hooks.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
Feature: Environment Hooks
Background:
Given a file named "features/a.feature" with:
"""
Feature: some feature
Scenario: some scenario
Given a step
"""
And a file named "features/step_definitions/cucumber_steps.js" with:
"""
const {Given} = require('@cucumber/cucumber')
Given(/^a step$/, function() {})
"""
Scenario: Hooks are steps
Given a file named "features/support/hooks.js" with:
"""
const {After, Before} = require('@cucumber/cucumber')
Before(function() {})
After(function() {})
"""
When I run cucumber-js
Then the scenario "some scenario" has the steps:
| IDENTIFIER |
| Before |
| Given a step |
| After |
Scenario: Failing before fails the scenario
Given a file named "features/support/hooks.js" with:
"""
const {Before} = require('@cucumber/cucumber')
Before(function() { throw 'Fail' })
"""
When I run cucumber-js
Then it fails
@spawn
Scenario: Failing after hook fails the scenario
Given a file named "features/support/hooks.js" with:
"""
const {After} = require('@cucumber/cucumber')
After(function() { throw 'Fail' })
"""
When I run cucumber-js
Then it fails
@spawn
Scenario: After hooks still execute after a failure
Given a file named "features/support/hooks.js" with:
"""
const {After, Before} = require('@cucumber/cucumber')
Before(function() { throw 'Fail' })
After(function() {})
"""
When I run cucumber-js
Then it fails
And scenario "some scenario" "After" hook has status "passed"
Scenario: World is this in hooks
Given a file named "features/support/world.js" with:
"""
const {setWorldConstructor} = require('@cucumber/cucumber')
function WorldConstructor() {
return {
isWorld: function() { return true }
}
}
setWorldConstructor(WorldConstructor)
"""
Given a file named "features/support/hooks.js" with:
"""
const {After, Before} = require('@cucumber/cucumber')
Before(function() {
if (!this.isWorld()) {
throw Error("Expected this to be world")
}
})
After(function() {
if (!this.isWorld()) {
throw Error("Expected this to be world")
}
})
"""
When I run cucumber-js
Then it passes