summaryrefslogtreecommitdiff
path: root/reuse/features/steps/reusable.js
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2018-12-27 08:47:18 +0100
committerEugen Wissner <belka@caraus.de>2018-12-27 08:47:18 +0100
commitfe4f62ff1a3346476aa6f4d025324d7d6cecf952 (patch)
tree6459e0bf13bf6199f817ec944319a9572e01bd24 /reuse/features/steps/reusable.js
parent0e8f395f7a9c422860f3f4c161788aca009d9889 (diff)
downloadcucumber-js-demo-fe4f62ff1a3346476aa6f4d025324d7d6cecf952.tar.gz
Add an example that reuses a step definition
Diffstat (limited to 'reuse/features/steps/reusable.js')
-rw-r--r--reuse/features/steps/reusable.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/reuse/features/steps/reusable.js b/reuse/features/steps/reusable.js
new file mode 100644
index 0000000..07ac8c5
--- /dev/null
+++ b/reuse/features/steps/reusable.js
@@ -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'])
+})