Skip to content

Commit

Permalink
fix(Table): constructor asserts param types (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
RedTn authored and buschtoens committed Dec 4, 2017
1 parent f5b56c9 commit 0d99b0f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions addon/classes/Table.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { A as emberArray } from '@ember/array';
import { assert } from '@ember/debug';
import EmberObject, { computed, get } from '@ember/object';
import Row from 'ember-light-table/classes/Row';
import Column from 'ember-light-table/classes/Column';
Expand Down Expand Up @@ -148,6 +149,9 @@ export default class Table extends EmberObject.extend({
constructor(columns = [], rows = [], options = {}) {
super();

assert('[ember-light-table] columns must be an array if defined', columns instanceof Array);
assert('[ember-light-table] rows must be an array if defined', rows instanceof Array);

let _options = mergeOptionsWithGlobals(options);
let _columns = emberArray(Table.createColumns(columns));
let _rows = emberArray(Table.createRows(rows, _options.rowOptions));
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/classes/table-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ test('create table - with options', function(assert) {
assert.ok(table.columns[0] instanceof Column);
});

test('create table - invalid constructor', function(assert) {
assert.expect(2);

assert.throws(() => {
new Table([{}, {}], null);
}, /\[ember-light-table] rows must be an array if defined/, 'rows is not an array');
assert.throws(() => {
new Table(null, [{}]);
}, /\[ember-light-table] columns must be an array if defined/, 'columns is not an array');
});

test('reopen table', function(assert) {
assert.equal(typeof Table.reopen, 'function', 'reopen is a function');
assert.equal(typeof Table.reopenClass, 'function', 'reopenClass is a function');
Expand Down

0 comments on commit 0d99b0f

Please sign in to comment.