1
0
cucumber-js-demo/data-tables/features/steps/json.js
2018-11-10 20:06:38 +01:00

51 lines
1.1 KiB
JavaScript

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))
})