mirror of
https://github.com/Leaflet/Leaflet.git
synced 2025-08-15 22:36:58 +00:00
Enable no-var
linting rule and fix issues (#8602)
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
/* eslint no-new: 0 */
|
||||
describe("Class", () => {
|
||||
describe("#extend", () => {
|
||||
var Klass,
|
||||
let Klass,
|
||||
props,
|
||||
constructor,
|
||||
method;
|
||||
@ -22,7 +22,7 @@ describe("Class", () => {
|
||||
});
|
||||
|
||||
it("creates a class with the given constructor & properties", () => {
|
||||
var a = new Klass();
|
||||
const a = new Klass();
|
||||
|
||||
expect(constructor.called).to.be.ok();
|
||||
expect(a.foo).to.eql(5);
|
||||
@ -33,9 +33,9 @@ describe("Class", () => {
|
||||
});
|
||||
|
||||
it("inherits parent classes' constructor & properties", () => {
|
||||
var Klass2 = Klass.extend({baz: 2});
|
||||
const Klass2 = Klass.extend({baz: 2});
|
||||
|
||||
var b = new Klass2();
|
||||
const b = new Klass2();
|
||||
|
||||
expect(b instanceof Klass).to.be.ok();
|
||||
expect(b instanceof Klass2).to.be.ok();
|
||||
@ -68,19 +68,19 @@ describe("Class", () => {
|
||||
});
|
||||
|
||||
it("inherits parent static properties", () => {
|
||||
var Klass2 = Klass.extend({});
|
||||
const Klass2 = Klass.extend({});
|
||||
|
||||
expect(Klass2.bla).to.eql(1);
|
||||
});
|
||||
|
||||
it("overrides parent static properties", () => {
|
||||
var Klass2 = Klass.extend({statics: {bla: 2}});
|
||||
const Klass2 = Klass.extend({statics: {bla: 2}});
|
||||
|
||||
expect(Klass2.bla).to.eql(2);
|
||||
});
|
||||
|
||||
it("includes the given mixin", () => {
|
||||
var a = new Klass();
|
||||
const a = new Klass();
|
||||
expect(a.mixin).to.be.ok();
|
||||
});
|
||||
|
||||
@ -89,10 +89,10 @@ describe("Class", () => {
|
||||
});
|
||||
|
||||
it("includes multiple mixins", () => {
|
||||
var Klass2 = L.Class.extend({
|
||||
const Klass2 = L.Class.extend({
|
||||
includes: [{mixin: true}, {mixin2: true}]
|
||||
});
|
||||
var a = new Klass2();
|
||||
const a = new Klass2();
|
||||
|
||||
expect(a.mixin).to.be.ok();
|
||||
expect(a.mixin2).to.be.ok();
|
||||
@ -101,67 +101,67 @@ describe("Class", () => {
|
||||
it("grants the ability to include the given mixin", () => {
|
||||
Klass.include({mixin2: true});
|
||||
|
||||
var a = new Klass();
|
||||
const a = new Klass();
|
||||
expect(a.mixin2).to.be.ok();
|
||||
});
|
||||
|
||||
it("merges options instead of replacing them", () => {
|
||||
var KlassWithOptions1 = L.Class.extend({
|
||||
const KlassWithOptions1 = L.Class.extend({
|
||||
options: {
|
||||
foo1: 1,
|
||||
foo2: 2
|
||||
}
|
||||
});
|
||||
var KlassWithOptions2 = KlassWithOptions1.extend({
|
||||
const KlassWithOptions2 = KlassWithOptions1.extend({
|
||||
options: {
|
||||
foo2: 3,
|
||||
foo3: 4
|
||||
}
|
||||
});
|
||||
|
||||
var a = new KlassWithOptions2();
|
||||
const a = new KlassWithOptions2();
|
||||
expect(a.options.foo1).to.eql(1);
|
||||
expect(a.options.foo2).to.eql(3);
|
||||
expect(a.options.foo3).to.eql(4);
|
||||
});
|
||||
|
||||
it("gives new classes a distinct options object", () => {
|
||||
var K1 = L.Class.extend({options: {}});
|
||||
var K2 = K1.extend({});
|
||||
const K1 = L.Class.extend({options: {}});
|
||||
const K2 = K1.extend({});
|
||||
expect(K2.prototype.options).not.to.equal(K1.prototype.options);
|
||||
});
|
||||
|
||||
it("inherits options prototypally", () => {
|
||||
var K1 = L.Class.extend({options: {}});
|
||||
var K2 = K1.extend({options: {}});
|
||||
const K1 = L.Class.extend({options: {}});
|
||||
const K2 = K1.extend({options: {}});
|
||||
K1.prototype.options.foo = 'bar';
|
||||
expect(K2.prototype.options.foo).to.eql('bar');
|
||||
});
|
||||
|
||||
it("does not reuse original props.options", () => {
|
||||
var props = {options: {}};
|
||||
var K = L.Class.extend(props);
|
||||
const props = {options: {}};
|
||||
const K = L.Class.extend(props);
|
||||
|
||||
expect(K.prototype.options).not.to.be(props.options);
|
||||
});
|
||||
|
||||
it("does not replace source props.options object", () => {
|
||||
var K1 = L.Class.extend({options: {}});
|
||||
var opts = {};
|
||||
var props = {options: opts};
|
||||
const K1 = L.Class.extend({options: {}});
|
||||
const opts = {};
|
||||
const props = {options: opts};
|
||||
K1.extend(props);
|
||||
|
||||
expect(props.options).to.be(opts);
|
||||
});
|
||||
|
||||
it("prevents change of prototype options", () => {
|
||||
var Klass = L.Class.extend({options: {}});
|
||||
var instance = new Klass();
|
||||
const Klass = L.Class.extend({options: {}});
|
||||
const instance = new Klass();
|
||||
expect(Klass.prototype.options).to.not.be(instance.options);
|
||||
});
|
||||
|
||||
it("adds constructor hooks correctly", () => {
|
||||
var spy1 = sinon.spy();
|
||||
const spy1 = sinon.spy();
|
||||
|
||||
Klass.addInitHook(spy1);
|
||||
Klass.addInitHook('bar', 1, 2, 3);
|
||||
@ -173,10 +173,10 @@ describe("Class", () => {
|
||||
});
|
||||
|
||||
it("inherits constructor hooks", () => {
|
||||
var spy1 = sinon.spy(),
|
||||
const spy1 = sinon.spy(),
|
||||
spy2 = sinon.spy();
|
||||
|
||||
var Klass2 = Klass.extend({});
|
||||
const Klass2 = Klass.extend({});
|
||||
|
||||
Klass.addInitHook(spy1);
|
||||
Klass2.addInitHook(spy2);
|
||||
@ -188,10 +188,10 @@ describe("Class", () => {
|
||||
});
|
||||
|
||||
it("does not call child constructor hooks", () => {
|
||||
var spy1 = sinon.spy(),
|
||||
const spy1 = sinon.spy(),
|
||||
spy2 = sinon.spy();
|
||||
|
||||
var Klass2 = Klass.extend({});
|
||||
const Klass2 = Klass.extend({});
|
||||
|
||||
Klass.addInitHook(spy1);
|
||||
Klass2.addInitHook(spy2);
|
||||
@ -203,11 +203,11 @@ describe("Class", () => {
|
||||
});
|
||||
|
||||
it("calls parent constructor hooks when child has none", () => {
|
||||
var spy1 = sinon.spy();
|
||||
const spy1 = sinon.spy();
|
||||
|
||||
Klass.addInitHook(spy1);
|
||||
|
||||
var Klass2 = Klass.extend({});
|
||||
const Klass2 = Klass.extend({});
|
||||
new Klass2();
|
||||
|
||||
expect(spy1.called).to.be.ok();
|
||||
@ -215,7 +215,7 @@ describe("Class", () => {
|
||||
});
|
||||
|
||||
describe("#include", () => {
|
||||
var Klass;
|
||||
let Klass;
|
||||
|
||||
beforeEach(() => {
|
||||
Klass = L.Class.extend({});
|
||||
@ -223,12 +223,12 @@ describe("Class", () => {
|
||||
|
||||
it("returns the class with the extra methods", () => {
|
||||
|
||||
var q = sinon.spy();
|
||||
const q = sinon.spy();
|
||||
|
||||
var Qlass = Klass.include({quux: q});
|
||||
const Qlass = Klass.include({quux: q});
|
||||
|
||||
var a = new Klass();
|
||||
var b = new Qlass();
|
||||
const a = new Klass();
|
||||
const b = new Qlass();
|
||||
|
||||
a.quux();
|
||||
expect(q.called).to.be.ok();
|
||||
@ -239,7 +239,7 @@ describe("Class", () => {
|
||||
|
||||
it("keeps parent options", () => { // #6070
|
||||
|
||||
var Quux = L.Class.extend({
|
||||
const Quux = L.Class.extend({
|
||||
options: {foo: 'Foo!'}
|
||||
});
|
||||
|
||||
@ -247,22 +247,22 @@ describe("Class", () => {
|
||||
options: {bar: 'Bar!'}
|
||||
});
|
||||
|
||||
var q = new Quux();
|
||||
const q = new Quux();
|
||||
expect(q.options).to.have.property('foo');
|
||||
expect(q.options).to.have.property('bar');
|
||||
});
|
||||
|
||||
it("does not reuse original props.options", () => {
|
||||
var props = {options: {}};
|
||||
var K = Klass.include(props);
|
||||
const props = {options: {}};
|
||||
const K = Klass.include(props);
|
||||
|
||||
expect(K.prototype.options).not.to.be(props.options);
|
||||
});
|
||||
|
||||
it("does not replace source props.options object", () => {
|
||||
var K1 = Klass.include({options: {}});
|
||||
var opts = {};
|
||||
var props = {options: opts};
|
||||
const K1 = Klass.include({options: {}});
|
||||
const opts = {};
|
||||
const props = {options: opts};
|
||||
K1.extend(props);
|
||||
|
||||
expect(props.options).to.be(opts);
|
||||
|
Reference in New Issue
Block a user