Make code prettier
This updates ESLint and our shared eslint-config-openlayers to use Prettier. Most formatting changes were automatically applied with this:
npm run lint -- --fix
A few manual changes were required:
* In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
* In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason. While editing this, I reworked `ExampleBuilder` to be a class.
* In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
This commit is contained in:
@@ -1,27 +1,23 @@
|
||||
import EventTarget from '../../../src/ol/events/Target.js';
|
||||
import Observable, {unByKey} from '../../../src/ol/Observable.js';
|
||||
|
||||
|
||||
describe('ol.Observable', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a new observable', function() {
|
||||
describe('ol.Observable', function () {
|
||||
describe('constructor', function () {
|
||||
it('creates a new observable', function () {
|
||||
const observable = new Observable();
|
||||
expect(observable).to.be.a(Observable);
|
||||
expect(observable).to.be.a(EventTarget);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#on()', function() {
|
||||
describe('#on()', function () {
|
||||
let observable, listener;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
observable = new Observable();
|
||||
listener = sinon.spy();
|
||||
});
|
||||
|
||||
it('registers a listener for events of the given type', function() {
|
||||
it('registers a listener for events of the given type', function () {
|
||||
observable.on('foo', listener);
|
||||
|
||||
observable.dispatchEvent('foo');
|
||||
@@ -31,7 +27,7 @@ describe('ol.Observable', function() {
|
||||
expect(listener.callCount).to.be(2);
|
||||
});
|
||||
|
||||
it('accepts an array of event types', function() {
|
||||
it('accepts an array of event types', function () {
|
||||
observable.on(['foo', 'bar'], listener);
|
||||
|
||||
observable.dispatchEvent('foo');
|
||||
@@ -41,22 +37,21 @@ describe('ol.Observable', function() {
|
||||
expect(listener.callCount).to.be(2);
|
||||
});
|
||||
|
||||
it('returns a listener key', function() {
|
||||
it('returns a listener key', function () {
|
||||
const key = observable.on('foo', listener);
|
||||
|
||||
expect(typeof key).to.be('object');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#once()', function() {
|
||||
describe('#once()', function () {
|
||||
let observable, listener;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
observable = new Observable();
|
||||
listener = sinon.spy();
|
||||
});
|
||||
|
||||
it('registers a listener that is only called once', function() {
|
||||
it('registers a listener that is only called once', function () {
|
||||
observable.once('foo', listener);
|
||||
|
||||
observable.dispatchEvent('foo');
|
||||
@@ -66,22 +61,22 @@ describe('ol.Observable', function() {
|
||||
expect(listener.callCount).to.be(1);
|
||||
});
|
||||
|
||||
it('is safe to dispatch events of same type in a once listener', function() {
|
||||
it('is safe to dispatch events of same type in a once listener', function () {
|
||||
let callCount = 0;
|
||||
observable.once('change', function() {
|
||||
observable.once('change', function () {
|
||||
observable.changed();
|
||||
observable.changed();
|
||||
});
|
||||
observable.on('change', function() {
|
||||
observable.on('change', function () {
|
||||
++callCount;
|
||||
});
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
observable.changed();
|
||||
}).to.not.throwException();
|
||||
expect(callCount).to.be(3);
|
||||
});
|
||||
|
||||
it('accepts an array of event types (called once for each)', function() {
|
||||
it('accepts an array of event types (called once for each)', function () {
|
||||
observable.once(['foo', 'bar'], listener);
|
||||
|
||||
observable.dispatchEvent('foo');
|
||||
@@ -97,22 +92,21 @@ describe('ol.Observable', function() {
|
||||
expect(listener.callCount).to.be(2);
|
||||
});
|
||||
|
||||
it('returns a listener key', function() {
|
||||
it('returns a listener key', function () {
|
||||
const key = observable.once('foo', listener);
|
||||
|
||||
expect(typeof key).to.be('object');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#un()', function() {
|
||||
describe('#un()', function () {
|
||||
let observable, listener;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
observable = new Observable();
|
||||
listener = sinon.spy();
|
||||
});
|
||||
|
||||
it('unregisters a previously registered listener', function() {
|
||||
it('unregisters a previously registered listener', function () {
|
||||
observable.on('foo', listener);
|
||||
|
||||
observable.dispatchEvent('foo');
|
||||
@@ -122,17 +116,16 @@ describe('ol.Observable', function() {
|
||||
observable.dispatchEvent('foo');
|
||||
expect(listener.calledOnce).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.Observable.unByKey()', function() {
|
||||
describe('ol.Observable.unByKey()', function () {
|
||||
let observable, listener;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
observable = new Observable();
|
||||
listener = sinon.spy();
|
||||
});
|
||||
|
||||
it('unregisters a listener given the key returned by `on`', function() {
|
||||
it('unregisters a listener given the key returned by `on`', function () {
|
||||
const key = observable.on('foo', listener);
|
||||
|
||||
observable.dispatchEvent('foo');
|
||||
@@ -142,7 +135,5 @@ describe('ol.Observable', function() {
|
||||
observable.dispatchEvent('foo');
|
||||
expect(listener.callCount).to.be(1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user