diff --git a/lib/data/dataTableArgument.js b/lib/data/dataTableArgument.js index b32953483..aceb328af 100644 --- a/lib/data/dataTableArgument.js +++ b/lib/data/dataTableArgument.js @@ -59,7 +59,7 @@ class DataTableArgument { /** Transposed the data */ transpose() { - this.rawData = this.rawData[0].map((x, i) => this.rawData.map((y) => y[i])); + this.rawData = this.rawData[0].map((_, i) => this.rawData.map((y) => y[i])); } } diff --git a/lib/data/table.js b/lib/data/table.js index 20981a65a..184b3c66c 100644 --- a/lib/data/table.js +++ b/lib/data/table.js @@ -1,14 +1,16 @@ +const DataTableArgument = require("./dataTableArgument"); + /** * Datatable class to provide data driven testing */ class DataTable { - /** @param {Array<*>} array */ + /** @param {Array} array */ constructor(array) { this.array = array; this.rows = new Array(0); } - /** @param {Array<*>} array */ + /** @param {Array} array */ add(array) { if (array.length !== this.array.length) throw new Error(`There is too many elements in given data array. Please provide data in this format: ${this.array}`); const tempObj = {}; @@ -21,7 +23,7 @@ class DataTable { this.rows.push({ skip: false, data: tempObj }); } - /** @param {Array<*>} array */ + /** @param {Array} array */ xadd(array) { if (array.length !== this.array.length) throw new Error(`There is too many elements in given data array. Please provide data in this format: ${this.array}`); const tempObj = {}; diff --git a/test/data/sandbox/features/step_definitions/my_other_steps.js b/test/data/sandbox/features/step_definitions/my_other_steps.js index a16033f94..225ca4e6f 100644 --- a/test/data/sandbox/features/step_definitions/my_other_steps.js +++ b/test/data/sandbox/features/step_definitions/my_other_steps.js @@ -1,6 +1,6 @@ const I = actor(); -Given('I have products in my cart', (table) => { // eslint-disable-line +Given('I have products in my cart', (table) => { for (const id in table.rows) { if (id < 1) { continue; diff --git a/typings/index.d.ts b/typings/index.d.ts index f8bc4ff33..0cb2d2a8b 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -356,6 +356,28 @@ declare namespace CodeceptJS { useForSnippets?: boolean preferForRegexpMatch?: boolean } + + interface DataTableArgument { + rawData: string[][]; + raw(): string[][]; + rows(): string[][]; + hashes(): { [columnHeader: string]: string }[]; + rowsHash(): { [columnHeader: string]: string }; + transpose(): string[][]; + } + + interface DataTable { + array: DataTableArgument[]; + rows: { + [key: string]: { + skip: boolean; + data: DataTableArgument; + } + }; + add: (array: DataTableArgument[]) => void; + xadd: (array: DataTableArgument[]) => void; + filter: (func: (item: DataTableArgument) => boolean) => DataTableArgument[]; + } } // Globals