summaryrefslogtreecommitdiff
path: root/data-tables/features/steps/json.js
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2018-11-10 20:06:38 +0100
committerEugen Wissner <belka@caraus.de>2018-11-10 20:06:38 +0100
commit15e5e413d9a49012202c46f8fde747c1593ec0f1 (patch)
treeb790d38e296e2979ce9b048f57852a04bba401ff /data-tables/features/steps/json.js
parent5d535973f330ede481f0bf2906ec187d726ddf80 (diff)
downloadcucumber-js-demo-15e5e413d9a49012202c46f8fde747c1593ec0f1.tar.gz
Add code
Diffstat (limited to 'data-tables/features/steps/json.js')
-rw-r--r--data-tables/features/steps/json.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/data-tables/features/steps/json.js b/data-tables/features/steps/json.js
new file mode 100644
index 0000000..cd61a8b
--- /dev/null
+++ b/data-tables/features/steps/json.js
@@ -0,0 +1,50 @@
+import { Given, When, Then } from 'cucumber'
+import { expect } from 'chai'
+
+Given('the following books by Simon Frank are in the collection:', function (dataTable) {
+ this.objects = []
+ dataTable.hashes().forEach(el => {
+ this.objects.push({
+ id: parseInt(el.id),
+ title: el.title
+ })
+ })
+})
+
+Given('the following books by Søren Kierkegaard are in the collection:', function (dataTable) {
+ this.objects = []
+ dataTable.rows().forEach(el => {
+ this.objects.push({
+ id: parseInt(el[0]),
+ title: el[1]
+ })
+ })
+})
+
+Given('the following book is in the collection:', function (dataTable) {
+ const data = dataTable.rowsHash()
+ this.objects = {
+ id: parseInt(data.id),
+ title: data.title,
+ author: data.author
+ }
+})
+
+Given('the following books are in the collection:', function (dataTable) {
+ this.objects = []
+ dataTable.raw().forEach(el => {
+ this.objects.push({
+ author: el[0],
+ title: el[1]
+ })
+ })
+})
+
+When('I stringify it', function () {
+ this.result = JSON.stringify(this.objects)
+})
+
+Then('I should get:', function (expected) {
+ expect(JSON.parse(expected))
+ .to.deep.equal(JSON.parse(this.result))
+})