After hook interface
Background:
- Given a file named "
features/my_feature.feature" with:
gherkinFeature: a feature
Scenario: a scenario
Given a step
- And a file named "
features/step_definitions/my_steps.js" with:
rubyconst {When} = require('@cucumber/cucumber')
When(/^a step$/, function() {
this.value = 1;
})
Scenario Outline: too many arguments
- Given a file named "
features/support/hooks.js" with:
rubyconst {<TYPE>} = require('@cucumber/cucumber')
<TYPE>(function(arg1, arg2, arg3) {})
- When I run cucumber-js
- Then it fails
- And the output contains the text:
textfunction has 3 arguments, should have 0 or 1 (if synchronous or returning a promise) or 2 (if accepting a callback)
Examples:
Scenario Outline: synchronous
- Given a file named "
features/support/hooks.js" with:
rubyconst {<TYPE>} = require('@cucumber/cucumber')
const assert = require('assert')
<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')
const assert = require('assert')
<TYPE>(function(scenario, 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(scenario, callback) {
setTimeout(() => {
callback(new Error('my error'))
})
})
- When I run cucumber-js
- Then it fails
Examples:
Scenario Outline: callback asynchronously throws
@spawn
- Given a file named "
features/support/hooks.js" with:
rubyconst {<TYPE>} = require('@cucumber/cucumber')
<TYPE>(function(scenario, callback) {
setTimeout(() => {
throw new Error('my error')
})
})
- When I run cucumber-js
- Then it fails
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(scenario, 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/hook_interface.feature at commit 3ac6ecda, Cucumber Js (MIT license).