Use blocked scoped variables
In addition to using const and let, this also upgrades our linter config and removes lint (mostly whitespace).
This commit is contained in:
@@ -9,29 +9,29 @@ describe('ol.Feature', function() {
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a new feature', function() {
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
expect(feature).to.be.a(Feature);
|
||||
});
|
||||
|
||||
it('takes properties', function() {
|
||||
var feature = new Feature({
|
||||
const feature = new Feature({
|
||||
foo: 'bar'
|
||||
});
|
||||
expect(feature.get('foo')).to.be('bar');
|
||||
});
|
||||
|
||||
it('can store the feature\'s commonly used id', function() {
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
feature.setId('foo');
|
||||
expect(feature.getId()).to.be('foo');
|
||||
});
|
||||
|
||||
it('will set the default geometry', function() {
|
||||
var feature = new Feature({
|
||||
const feature = new Feature({
|
||||
geometry: new Point([10, 20]),
|
||||
foo: 'bar'
|
||||
});
|
||||
var geometry = feature.getGeometry();
|
||||
const geometry = feature.getGeometry();
|
||||
expect(geometry).to.be.a(Point);
|
||||
expect(feature.get('geometry')).to.be(geometry);
|
||||
});
|
||||
@@ -41,7 +41,7 @@ describe('ol.Feature', function() {
|
||||
describe('#get()', function() {
|
||||
|
||||
it('returns values set at construction', function() {
|
||||
var feature = new Feature({
|
||||
const feature = new Feature({
|
||||
a: 'first',
|
||||
b: 'second'
|
||||
});
|
||||
@@ -50,12 +50,12 @@ describe('ol.Feature', function() {
|
||||
});
|
||||
|
||||
it('returns undefined for unset attributes', function() {
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
expect(feature.get('a')).to.be(undefined);
|
||||
});
|
||||
|
||||
it('returns values set by set', function() {
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
feature.set('a', 'b');
|
||||
expect(feature.get('a')).to.be('b');
|
||||
});
|
||||
@@ -65,16 +65,16 @@ describe('ol.Feature', function() {
|
||||
describe('#getProperties()', function() {
|
||||
|
||||
it('returns an object with all attributes', function() {
|
||||
var point = new Point([15, 30]);
|
||||
var feature = new Feature({
|
||||
const point = new Point([15, 30]);
|
||||
const feature = new Feature({
|
||||
foo: 'bar',
|
||||
ten: 10,
|
||||
geometry: point
|
||||
});
|
||||
|
||||
var attributes = feature.getProperties();
|
||||
const attributes = feature.getProperties();
|
||||
|
||||
var keys = Object.keys(attributes);
|
||||
const keys = Object.keys(attributes);
|
||||
expect(keys.sort()).to.eql(['foo', 'geometry', 'ten']);
|
||||
|
||||
expect(attributes.foo).to.be('bar');
|
||||
@@ -83,8 +83,8 @@ describe('ol.Feature', function() {
|
||||
});
|
||||
|
||||
it('is empty by default', function() {
|
||||
var feature = new Feature();
|
||||
var properties = feature.getProperties();
|
||||
const feature = new Feature();
|
||||
const properties = feature.getProperties();
|
||||
expect(_ol_obj_.isEmpty(properties)).to.be(true);
|
||||
});
|
||||
|
||||
@@ -93,37 +93,37 @@ describe('ol.Feature', function() {
|
||||
|
||||
describe('#getGeometry()', function() {
|
||||
|
||||
var point = new Point([15, 30]);
|
||||
const point = new Point([15, 30]);
|
||||
|
||||
it('returns undefined for unset geometry', function() {
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
expect(feature.getGeometry()).to.be(undefined);
|
||||
});
|
||||
|
||||
it('returns null for null geometry (constructor)', function() {
|
||||
var feature = new Feature(null);
|
||||
const feature = new Feature(null);
|
||||
expect(feature.getGeometry()).to.be(null);
|
||||
});
|
||||
|
||||
it('returns null for null geometry (setGeometry())', function() {
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
feature.setGeometry(null);
|
||||
expect(feature.getGeometry()).to.be(null);
|
||||
});
|
||||
|
||||
it('gets the geometry set at construction', function() {
|
||||
var feature = new Feature({
|
||||
const feature = new Feature({
|
||||
geometry: point
|
||||
});
|
||||
expect(feature.getGeometry()).to.be(point);
|
||||
});
|
||||
|
||||
it('gets any geometry set by setGeometry', function() {
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
feature.setGeometry(point);
|
||||
expect(feature.getGeometry()).to.be(point);
|
||||
|
||||
var point2 = new Point([1, 2]);
|
||||
const point2 = new Point([1, 2]);
|
||||
feature.setGeometry(point2);
|
||||
expect(feature.getGeometry()).to.be(point2);
|
||||
});
|
||||
@@ -133,7 +133,7 @@ describe('ol.Feature', function() {
|
||||
describe('#set()', function() {
|
||||
|
||||
it('sets values', function() {
|
||||
var feature = new Feature({
|
||||
const feature = new Feature({
|
||||
a: 'first',
|
||||
b: 'second'
|
||||
});
|
||||
@@ -142,8 +142,8 @@ describe('ol.Feature', function() {
|
||||
});
|
||||
|
||||
it('can be used to set the geometry', function() {
|
||||
var point = new Point([3, 4]);
|
||||
var feature = new Feature({
|
||||
const point = new Point([3, 4]);
|
||||
const feature = new Feature({
|
||||
geometry: new Point([1, 2])
|
||||
});
|
||||
feature.set('geometry', point);
|
||||
@@ -153,7 +153,7 @@ describe('ol.Feature', function() {
|
||||
|
||||
it('can be used to set attributes with arbitrary names', function() {
|
||||
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
|
||||
feature.set('toString', 'string');
|
||||
expect(feature.get('toString')).to.be('string');
|
||||
@@ -171,21 +171,21 @@ describe('ol.Feature', function() {
|
||||
|
||||
describe('#setGeometry()', function() {
|
||||
|
||||
var point = new Point([15, 30]);
|
||||
const point = new Point([15, 30]);
|
||||
|
||||
it('sets the default geometry', function() {
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
feature.setGeometry(point);
|
||||
expect(feature.get('geometry')).to.be(point);
|
||||
});
|
||||
|
||||
it('replaces previous default geometry', function() {
|
||||
var feature = new Feature({
|
||||
const feature = new Feature({
|
||||
geometry: point
|
||||
});
|
||||
expect(feature.getGeometry()).to.be(point);
|
||||
|
||||
var point2 = new Point([1, 2]);
|
||||
const point2 = new Point([1, 2]);
|
||||
feature.setGeometry(point2);
|
||||
expect(feature.getGeometry()).to.be(point2);
|
||||
});
|
||||
@@ -194,14 +194,14 @@ describe('ol.Feature', function() {
|
||||
|
||||
describe('#setGeometryName()', function() {
|
||||
|
||||
var point = new Point([15, 30]);
|
||||
const point = new Point([15, 30]);
|
||||
|
||||
it('sets property where to to look at geometry', function() {
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
feature.setGeometry(point);
|
||||
expect(feature.getGeometry()).to.be(point);
|
||||
|
||||
var point2 = new Point([1, 2]);
|
||||
const point2 = new Point([1, 2]);
|
||||
feature.set('altGeometry', point2);
|
||||
expect(feature.getGeometry()).to.be(point);
|
||||
feature.setGeometryName('altGeometry');
|
||||
@@ -214,22 +214,22 @@ describe('ol.Feature', function() {
|
||||
});
|
||||
|
||||
it('changes property listener', function() {
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
feature.setGeometry(point);
|
||||
var point2 = new Point([1, 2]);
|
||||
const point2 = new Point([1, 2]);
|
||||
feature.set('altGeometry', point2);
|
||||
feature.setGeometryName('altGeometry');
|
||||
|
||||
var spy = sinon.spy();
|
||||
const spy = sinon.spy();
|
||||
feature.on('change', spy);
|
||||
point2.setCoordinates([0, 2]);
|
||||
expect(spy.callCount).to.be(1);
|
||||
});
|
||||
|
||||
it('can use a different geometry name', function() {
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
feature.setGeometryName('foo');
|
||||
var point = new Point([10, 20]);
|
||||
const point = new Point([10, 20]);
|
||||
feature.setGeometry(point);
|
||||
expect(feature.getGeometry()).to.be(point);
|
||||
});
|
||||
@@ -239,14 +239,14 @@ describe('ol.Feature', function() {
|
||||
describe('#setId()', function() {
|
||||
|
||||
it('sets the feature identifier', function() {
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
expect(feature.getId()).to.be(undefined);
|
||||
feature.setId('foo');
|
||||
expect(feature.getId()).to.be('foo');
|
||||
});
|
||||
|
||||
it('accepts a string or number', function() {
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
feature.setId('foo');
|
||||
expect(feature.getId()).to.be('foo');
|
||||
feature.setId(2);
|
||||
@@ -254,7 +254,7 @@ describe('ol.Feature', function() {
|
||||
});
|
||||
|
||||
it('dispatches the "change" event', function(done) {
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
feature.on('change', function() {
|
||||
expect(feature.getId()).to.be('foo');
|
||||
done();
|
||||
@@ -266,29 +266,29 @@ describe('ol.Feature', function() {
|
||||
|
||||
describe('#getStyleFunction()', function() {
|
||||
|
||||
var styleFunction = function(resolution) {
|
||||
const styleFunction = function(resolution) {
|
||||
return null;
|
||||
};
|
||||
|
||||
it('returns undefined after construction', function() {
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
expect(feature.getStyleFunction()).to.be(undefined);
|
||||
});
|
||||
|
||||
it('returns the function passed to setStyle', function() {
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
feature.setStyle(styleFunction);
|
||||
expect(feature.getStyleFunction()).to.be(styleFunction);
|
||||
});
|
||||
|
||||
it('does not get confused with user "styleFunction" property', function() {
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
feature.set('styleFunction', 'foo');
|
||||
expect(feature.getStyleFunction()).to.be(undefined);
|
||||
});
|
||||
|
||||
it('does not get confused with "styleFunction" option', function() {
|
||||
var feature = new Feature({
|
||||
const feature = new Feature({
|
||||
styleFunction: 'foo'
|
||||
});
|
||||
expect(feature.getStyleFunction()).to.be(undefined);
|
||||
@@ -298,28 +298,28 @@ describe('ol.Feature', function() {
|
||||
|
||||
describe('#setStyle()', function() {
|
||||
|
||||
var style = new Style();
|
||||
const style = new Style();
|
||||
|
||||
var styleFunction = function(feature, resolution) {
|
||||
const styleFunction = function(feature, resolution) {
|
||||
return resolution;
|
||||
};
|
||||
|
||||
it('accepts a single style', function() {
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
feature.setStyle(style);
|
||||
var func = feature.getStyleFunction();
|
||||
const func = feature.getStyleFunction();
|
||||
expect(func()).to.eql([style]);
|
||||
});
|
||||
|
||||
it('accepts an array of styles', function() {
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
feature.setStyle([style]);
|
||||
var func = feature.getStyleFunction();
|
||||
const func = feature.getStyleFunction();
|
||||
expect(func()).to.eql([style]);
|
||||
});
|
||||
|
||||
it('accepts a style function', function() {
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
function featureStyleFunction(resolution) {
|
||||
return styleFunction(this, resolution);
|
||||
}
|
||||
@@ -329,14 +329,14 @@ describe('ol.Feature', function() {
|
||||
});
|
||||
|
||||
it('accepts a layer style function', function() {
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
feature.setStyle(styleFunction);
|
||||
expect(feature.getStyleFunction()).to.not.be(styleFunction);
|
||||
expect(feature.getStyleFunction()(42)).to.be(42);
|
||||
});
|
||||
|
||||
it('accepts null', function() {
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
feature.setStyle(style);
|
||||
feature.setStyle(null);
|
||||
expect(feature.getStyle()).to.be(null);
|
||||
@@ -344,8 +344,8 @@ describe('ol.Feature', function() {
|
||||
});
|
||||
|
||||
it('dispatches a change event', function() {
|
||||
var feature = new Feature();
|
||||
var spy = sinon.spy();
|
||||
const feature = new Feature();
|
||||
const spy = sinon.spy();
|
||||
feature.on('change', spy);
|
||||
feature.setStyle(style);
|
||||
expect(spy.callCount).to.be(1);
|
||||
@@ -355,14 +355,14 @@ describe('ol.Feature', function() {
|
||||
|
||||
describe('#getStyle()', function() {
|
||||
|
||||
var style = new Style();
|
||||
const style = new Style();
|
||||
|
||||
var styleFunction = function(resolution) {
|
||||
const styleFunction = function(resolution) {
|
||||
return null;
|
||||
};
|
||||
|
||||
it('returns what is passed to setStyle', function() {
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
|
||||
expect(feature.getStyle()).to.be(null);
|
||||
|
||||
@@ -378,7 +378,7 @@ describe('ol.Feature', function() {
|
||||
});
|
||||
|
||||
it('does not get confused with "style" option to constructor', function() {
|
||||
var feature = new Feature({
|
||||
const feature = new Feature({
|
||||
style: 'foo'
|
||||
});
|
||||
|
||||
@@ -386,7 +386,7 @@ describe('ol.Feature', function() {
|
||||
});
|
||||
|
||||
it('does not get confused with user set "style" property', function() {
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
feature.set('style', 'foo');
|
||||
|
||||
expect(feature.getStyle()).to.be(null);
|
||||
@@ -397,23 +397,23 @@ describe('ol.Feature', function() {
|
||||
describe('#clone', function() {
|
||||
|
||||
it('correctly clones features', function() {
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
feature.setProperties({'fookey': 'fooval'});
|
||||
feature.setId(1);
|
||||
feature.setGeometryName('geom');
|
||||
var geometry = new Point([1, 2]);
|
||||
const geometry = new Point([1, 2]);
|
||||
feature.setGeometry(geometry);
|
||||
var style = new Style({});
|
||||
const style = new Style({});
|
||||
feature.setStyle(style);
|
||||
feature.set('barkey', 'barval');
|
||||
|
||||
var clone = feature.clone();
|
||||
const clone = feature.clone();
|
||||
expect(clone.get('fookey')).to.be('fooval');
|
||||
expect(clone.getId()).to.be(undefined);
|
||||
expect(clone.getGeometryName()).to.be('geom');
|
||||
var geometryClone = clone.getGeometry();
|
||||
const geometryClone = clone.getGeometry();
|
||||
expect(geometryClone).not.to.be(geometry);
|
||||
var coordinates = geometryClone.getFlatCoordinates();
|
||||
const coordinates = geometryClone.getFlatCoordinates();
|
||||
expect(coordinates[0]).to.be(1);
|
||||
expect(coordinates[1]).to.be(2);
|
||||
expect(clone.getStyle()).to.be(style);
|
||||
@@ -421,10 +421,10 @@ describe('ol.Feature', function() {
|
||||
});
|
||||
|
||||
it('correctly clones features with no geometry and no style', function() {
|
||||
var feature = new Feature();
|
||||
const feature = new Feature();
|
||||
feature.set('fookey', 'fooval');
|
||||
|
||||
var clone = feature.clone();
|
||||
const clone = feature.clone();
|
||||
expect(clone.get('fookey')).to.be('fooval');
|
||||
expect(clone.getGeometry()).to.be(undefined);
|
||||
expect(clone.getStyle()).to.be(null);
|
||||
@@ -434,37 +434,37 @@ describe('ol.Feature', function() {
|
||||
describe('#setGeometry()', function() {
|
||||
|
||||
it('dispatches a change event when geometry is set to null',
|
||||
function() {
|
||||
var feature = new Feature({
|
||||
geometry: new Point([0, 0])
|
||||
});
|
||||
var spy = sinon.spy();
|
||||
feature.on('change', spy);
|
||||
feature.setGeometry(null);
|
||||
expect(spy.callCount).to.be(1);
|
||||
function() {
|
||||
const feature = new Feature({
|
||||
geometry: new Point([0, 0])
|
||||
});
|
||||
const spy = sinon.spy();
|
||||
feature.on('change', spy);
|
||||
feature.setGeometry(null);
|
||||
expect(spy.callCount).to.be(1);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.Feature.createStyleFunction()', function() {
|
||||
var style = new Style();
|
||||
const style = new Style();
|
||||
|
||||
it('creates a feature style function from a single style', function() {
|
||||
var styleFunction = Feature.createStyleFunction(style);
|
||||
const styleFunction = Feature.createStyleFunction(style);
|
||||
expect(styleFunction()).to.eql([style]);
|
||||
});
|
||||
|
||||
it('creates a feature style function from an array of styles', function() {
|
||||
var styleFunction = Feature.createStyleFunction([style]);
|
||||
const styleFunction = Feature.createStyleFunction([style]);
|
||||
expect(styleFunction()).to.eql([style]);
|
||||
});
|
||||
|
||||
it('passes through a function', function() {
|
||||
var original = function() {
|
||||
const original = function() {
|
||||
return [style];
|
||||
};
|
||||
var styleFunction = Feature.createStyleFunction(original);
|
||||
const styleFunction = Feature.createStyleFunction(original);
|
||||
expect(styleFunction).to.be(original);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user