Add an example that reuses a step definition
This commit is contained in:
parent
0e8f395f7a
commit
fe4f62ff1a
@ -47,3 +47,11 @@ Shows how to use promises and `async`/`await` when testing asynchronous code.
|
||||
### ts
|
||||
|
||||
Defining steps in TypeScript.
|
||||
|
||||
### type-parser
|
||||
|
||||
Defines custom parameter types.
|
||||
|
||||
### reuse
|
||||
|
||||
Suggests a way to reuse step definitions.
|
||||
|
7
reuse/babel.config.js
Normal file
7
reuse/babel.config.js
Normal file
@ -0,0 +1,7 @@
|
||||
module.exports = {
|
||||
presets: [
|
||||
[ '@babel/env', {
|
||||
useBuiltIns: 'usage'
|
||||
}]
|
||||
]
|
||||
}
|
5
reuse/features/reusable.feature
Normal file
5
reuse/features/reusable.feature
Normal file
@ -0,0 +1,5 @@
|
||||
Feature:
|
||||
Scenario:
|
||||
Given a person with name
|
||||
And a person named Jack
|
||||
Then the same function is called for two distinct step definitions
|
28
reuse/features/steps/reusable.js
Normal file
28
reuse/features/steps/reusable.js
Normal file
@ -0,0 +1,28 @@
|
||||
import { Before, Given, Then } from 'cucumber'
|
||||
import { expect } from 'chai'
|
||||
|
||||
Before(function () {
|
||||
this.names = []
|
||||
})
|
||||
|
||||
function step (name) {
|
||||
this.names.push(name)
|
||||
}
|
||||
|
||||
function decorator (f, ...args) {
|
||||
if (args.length > 0) {
|
||||
return function () {
|
||||
f.call(this, args[0])
|
||||
}
|
||||
} else {
|
||||
return f
|
||||
}
|
||||
}
|
||||
|
||||
Given('a person with name', decorator(step, 'John'))
|
||||
Given('a person named {word}', decorator(step))
|
||||
|
||||
Then('the same function is called for two distinct step definitions', function () {
|
||||
expect(this.names).to.have.lengthOf(2)
|
||||
expect(this.names).to.include.members(['John', 'Jack'])
|
||||
})
|
2015
reuse/package-lock.json
generated
Normal file
2015
reuse/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
19
reuse/package.json
Normal file
19
reuse/package.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "reuse",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "cucumber-js --require-module '@babel/register'"
|
||||
},
|
||||
"author": "Eugen Wissner <belka@caraus.de>",
|
||||
"license": "MPL-2.0",
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.2.2",
|
||||
"@babel/preset-env": "^7.2.3",
|
||||
"@babel/register": "^7.0.0",
|
||||
"babel-loader": "^8.0.4",
|
||||
"chai": "^4.2.0",
|
||||
"cucumber": "^5.0.3"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user