Skip to content

Commit

Permalink
list, operations validation in constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosrberto committed Apr 2, 2018
1 parent 35aed17 commit 2693acb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/LazyList.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ export const VALID_OPERATIONS = Object

export default class LazyList {
constructor(list, operations = []) {
if (!Array.isArray(list)) {
throw Error('Invalid list argument');
}

if (!Array.isArray(operations)) {
throw Error('Invalid operations argument');
}

this.operations = operations;
this.list = list;
}
Expand Down
18 changes: 17 additions & 1 deletion src/LazyList.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
import lazy from './index';
import { LIST_OPERATIONS } from './LazyList';
import LazyList, { LIST_OPERATIONS } from './LazyList';

describe('LazyList.constructor', () => {
it('should throw when invalid list is provided', () => {
expect(() => {
const list = () => new LazyList(null);
list();
}).toThrowError('Invalid list argument');
});

it('should throw when invalid operations is provided', () => {
expect(() => {
const list = () => new LazyList([], null);
list();
}).toThrowError('Invalid operations argument');
});
});

describe('LazyList.createOperation', () => {
it('should throw when invalid operation is provided', () => {
Expand Down

0 comments on commit 2693acb

Please sign in to comment.