Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/table constructor #522

Merged
merged 2 commits into from
Dec 4, 2017
Merged
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
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