Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/runner/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,18 @@ module.exports = {
* @return {Any} - The data for the iteration
*/
getIterationData (data, iteration) {
// if iteration has a corresponding data element use that
if (!Array.isArray(data) || !data.length) {
return;
}

if (iteration < 0) {
return data[0];
}

if (iteration < data.length) {
return data[iteration];
}

// otherwise use the last data element
return data[data.length - 1];
},

Expand Down
10 changes: 10 additions & 0 deletions test/unit/runner-util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ describe('runner util', function () {
});

describe('.getIterationData', function () {
it('should handle negative iteration index', function () {
var data = [
{ value: 'first' },
{ value: 'second' }
],
result = runnerUtil.getIterationData(data, -1);

expect(result).to.equal(data[0]);
});

it('should return data for the specified iteration', function () {
var data = [
{ iteration: 0, value: 'first' },
Expand Down