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 Layer#checkProp to only error on undefined/null #39

Merged
merged 2 commits into from
Jul 1, 2016
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
7 changes: 4 additions & 3 deletions src/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export default class Layer {
assert(props.data[Symbol.iterator], 'data prop must have an iterator');
}

this.props = props;

this.checkProp(props.data, 'data');
this.checkProp(props.id, 'id');
this.checkProp(props.width, 'width');
Expand All @@ -103,7 +105,6 @@ export default class Layer {
this.checkProp(props.longitude, 'longitude');
this.checkProp(props.zoom, 'zoom');

this.props = props;
this.count = counter++;
}
/* eslint-enable max-statements */
Expand Down Expand Up @@ -455,8 +456,8 @@ export default class Layer {
}

checkProp(property, propertyName) {
if (!property) {
throw new Error(`Property ${propertyName} undefined in layer ${this.id}`);
if (property === undefined || property === null) {
throw new Error(`Property ${propertyName} undefined in layer ${this.props.id}`);
}
}

Expand Down
32 changes: 32 additions & 0 deletions test/layer-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,45 @@ const LAYER_PROPS = {
zoom: 1,
data: []
};
const LAYER_PROPS_ZEROES = {
id: 'testLayer',
width: 0,
height: 0,
latitude: 0,
longitude: 0,
zoom: 0,
data: []
};
const LAYER_PROPS_MISSING = {
id: 'testLayer',
width: 1,
// height: 1,
longitude: 1,
zoom: 1,
data: []
}

test('Layer#constructor', t => {
const layer = new Layer(LAYER_PROPS);
t.ok(layer, 'Layer created');
t.end();
});

test('Layer#constructor with zeroes', t => {
const layer = new Layer(LAYER_PROPS_ZEROES);
t.ok(layer, 'Layer created');
t.end();
});

test('Layer#constructor with missing props', t => {
t.throws(
() => new Layer(LAYER_PROPS_MISSING),
/Property height undefined in layer testLayer/,
'Expected missing props to throw an error'
);
t.end();
});

test('Layer#getNumInstances', t => {
for (const dataVariant of dataVariants) {
const layer = new Layer({
Expand Down