Skip to content

Commit

Permalink
Merge pull request #47 from pat310/43filterError
Browse files Browse the repository at this point in the history
43filter error
  • Loading branch information
pat310 committed Apr 13, 2017
2 parents 8969111 + 812bc6a commit e27daf3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,14 @@ export function checkPivotCategories(actualCats, selectedCats) {
export function tableCreator(data, rows = [], cols = [], accCatOrCB,
accTypeOrInitVal, rowHeader) {

/** */
/** if data is empty, return empty array */
if (data.length === 0) return [];

/** if rows/cols are not arrays, return throw an error */
if (!Array.isArray(rows) || !Array.isArray(cols)) {
throw new Error('rowsToPivot and colsToPivot must be of type array');
}

checkPivotCategories(data[0], rows);
checkPivotCategories(data[0], cols);

Expand Down
10 changes: 10 additions & 0 deletions test/logic/tableCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,14 @@ export default () => {
expect(tableResults.table).to.deep.equal(expectedResults);
});

it('should throw an error if rows/cols are not provided as an array', () => {
const rowError = tableCreator.bind(null, data, 'gender', ['house'], 'age',
'count');
const colError = tableCreator.bind(null, data, ['gender'], 'house', 'age',
'count');

expect(rowError).to.throw(Error);
expect(colError).to.throw(Error);
});

};

0 comments on commit e27daf3

Please sign in to comment.