Last active
July 4, 2023 06:54
-
-
Save wswebcreation/ae98ecf66aedd7b1037cfe70b188c26c to your computer and use it in GitHub Desktop.
The difference in `table.hashes()` and `table.rowsHash()` in CucumberJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Given } from 'cucumber'; | |
/** | |
* Transform a cucumberjs data table to an Array | |
* | |
* @example | |
* <pre> | |
* // insert from featurefile | |
* Given a table hashes step | |
* | Vegetable | Rating | | |
* | Apricot | 5 | | |
* | Broccoli | 2 | | |
* | Cucumber | 10 | | |
* | |
* // returns | |
* const result = [ | |
* {'Vegetable': 'Apricot', 'Rating': '5'}, | |
* {'Vegetable': 'Broccoli', 'Rating': '2'}, | |
* {'Vegetable': 'Cucumber', 'Rating': '10'} | |
* ]; | |
* </pre> | |
* | |
* @return {Array} | |
*/ | |
Given( | |
/a table hashes step/, | |
(table) => { | |
const result = table.hashes(); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Given } from 'cucumber'; | |
/** | |
* Transform a cucumberjs data table to an object | |
* | |
* @example | |
* <pre> | |
* // insert from featurefile | |
* Given a table row hash step | |
* | Apricot | 5 | | |
* | Broccoli | 2 | | |
* | Cucumber | 10 | | |
* | |
* // returns | |
* const result = { | |
* Apricot: 5, | |
* Broccoli: 2, | |
* Cucumber: 10 | |
* } | |
* </pre> | |
* | |
* @return {Object} | |
*/ | |
Given( | |
/a table row hash step/, | |
(table) => { | |
const result = table.rowsHash(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment