before / after all hook interfaces
Rules:
- before / after all hooks can be synchronous, return a promise, or accept a callback
Background:
- Given a file named "
features/a.feature" with:
gherkinFeature: some feature
Scenario: first scenario
Given first step
Scenario: second scenario
Given second step
- And a file named "
features/step_definitions/my_steps.js" with:
rubyconst {Given} = require('@cucumber/cucumber')
Given('first step', function() {})
Given('second step', function() {})
Scenario Outline: synchronous
- Given a file named "
features/support/hooks.js" with:
rubyconst {<TYPE>} = require('@cucumber/cucumber')
<TYPE>(function() {})
- When I run cucumber-js
- Then it passes
Examples:
Scenario Outline: synchronously throws
- Given a file named "
features/support/hooks.js" with:
rubyconst {<TYPE>} = require('@cucumber/cucumber')
<TYPE>(function() {
throw new Error('my error')
})
- When I run cucumber-js
- Then it fails
Examples:
Scenario Outline: callback without error
- Given a file named "
features/support/hooks.js" with:
rubyconst {<TYPE>} = require('@cucumber/cucumber')
<TYPE>(function(callback) {
setTimeout(callback)
})
- When I run cucumber-js
- Then it passes
Examples:
Scenario Outline: callback with error
- Given a file named "
features/support/hooks.js" with:
rubyconst {<TYPE>} = require('@cucumber/cucumber')
<TYPE>(function(callback) {
setTimeout(() => {
callback(new Error('my error'))
})
})
- When I run cucumber-js
- Then it fails
- And the output contains the text:
Examples:
Scenario Outline: callback asynchronously throws
@spawn
- Given a file named "
features/support/hooks.js" with:
rubyconst {<TYPE>} = require('@cucumber/cucumber')
<TYPE>(function(callback) {
setTimeout(() => {
throw new Error('my error')
})
})
- When I run cucumber-js
- Then it fails
- And the output contains the text:
Examples:
Scenario Outline: callback - returning a promise
- Given a file named "
features/step_definitions/failing_steps.js" with:
rubyconst {<TYPE>} = require('@cucumber/cucumber')
<TYPE>(function(callback) {
return Promise.resolve()
})
- When I run cucumber-js
- Then it fails
- And the output contains the text:
textfunction 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
Examples:
Scenario Outline: promise resolves
- Given a file named "
features/support/hooks.js" with:
rubyconst {<TYPE>} = require('@cucumber/cucumber')
<TYPE>(function() {
return Promise.resolve()
})
- When I run cucumber-js
- Then it passes
Examples:
Scenario Outline: promise rejects with error
- Given a file named "
features/support/hooks.js" with:
rubyconst {<TYPE>} = require('@cucumber/cucumber')
<TYPE>(function() {
return Promise.reject(new Error('my error'))
})
- When I run cucumber-js
- Then it fails
- And the output contains the text:
Examples:
Scenario Outline: promise rejects without error
- Given a file named "
features/support/hooks.js" with:
rubyconst {<TYPE>} = require('@cucumber/cucumber')
<TYPE>(function() {
return Promise.reject()
})
- When I run cucumber-js
- Then it fails
- And the output contains the text:
textPromise rejected without a reason
Examples:
Scenario Outline: promise asynchronously throws
@spawn
- Given a file named "
features/support/hooks.js" with:
rubyconst {<TYPE>} = require('@cucumber/cucumber')
<TYPE>(function() {
return new Promise(function() {
setTimeout(() => {
throw new Error('my error')
})
})
})
- When I run cucumber-js
- Then it fails
- And the output contains the text:
Examples:
Source: features/before_after_all_hook_interfaces.feature at commit 3ac6ecda, Cucumber Js (MIT license).