Skip to content

Instantly share code, notes, and snippets.

@wswebcreation
Last active July 4, 2023 06:54
Show Gist options
  • Save wswebcreation/ae98ecf66aedd7b1037cfe70b188c26c to your computer and use it in GitHub Desktop.
Save wswebcreation/ae98ecf66aedd7b1037cfe70b188c26c to your computer and use it in GitHub Desktop.
The difference in `table.hashes()` and `table.rowsHash()` in CucumberJS
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();
});
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