diff --git a/addon/classes/Table.js b/addon/classes/Table.js index faba9ef0..561f8d2c 100644 --- a/addon/classes/Table.js +++ b/addon/classes/Table.js @@ -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'; @@ -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)); diff --git a/tests/unit/classes/table-test.js b/tests/unit/classes/table-test.js index f23c8e9d..49b13d9e 100644 --- a/tests/unit/classes/table-test.js +++ b/tests/unit/classes/table-test.js @@ -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');