Skip to content

Commit

Permalink
jshinting and major clean up of specs code, ref Leaflet#2151
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner committed Nov 7, 2013
1 parent 4f9e9a7 commit 91c039b
Show file tree
Hide file tree
Showing 28 changed files with 327 additions and 300 deletions.
25 changes: 25 additions & 0 deletions spec/spec.hintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"browser": true,
"node": true,
"predef": ["define", "L", "expect", "describe", "it", "sinon", "happen", "beforeEach", "afterEach"],
"strict": false,
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"forin": false,
"immed": true,
"latedef": true,
"newcap": true,
"noarg": true,
"noempty": true,
"nonew": true,
"undef": true,
// "unused": true,
// "quotmark": "single",
"indent": 4,
"trailing": true,
"white": true,
"smarttabs": true
// "maxlen": 120
}
4 changes: 2 additions & 2 deletions spec/suites/LeafletSpec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('L#noConflict', function() {
it('restores the previous L value and returns Leaflet namespace', function(){
describe('L#noConflict', function () {
it('restores the previous L value and returns Leaflet namespace', function () {

expect(L.version).to.be.ok();

Expand Down
66 changes: 33 additions & 33 deletions spec/suites/SpecHelper.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
function noSpecs() {
xit('has no specs');
}

if (!Array.prototype.map) {
Array.prototype.map = function(fun /*, thisp */) {
"use strict";
Array.prototype.map = function (fun /*, thisp */) {
"use strict";

if (this === void 0 || this === null)
throw new TypeError();
if (this === void 0 || this === null) {
throw new TypeError();
}

var t = Object(this);
var len = t.length >>> 0;
if (typeof fun !== "function")
throw new TypeError();
var t = Object(this);
// jshint bitwise: false
var len = t.length >>> 0;
if (typeof fun !== "function") {
throw new TypeError();
}

var res = new Array(len);
var thisp = arguments[1];
for (var i = 0; i < len; i++) {
if (i in t)
res[i] = fun.call(thisp, t[i], i, t);
}
var res = new Array(len);
var thisp = arguments[1];
for (var i = 0; i < len; i++) {
if (i in t) {
res[i] = fun.call(thisp, t[i], i, t);
}
}

return res;
};
return res;
};
}

expect.Assertion.prototype.near = function(expected, delta) {
delta = delta || 1;
expect(this.obj.x).to
.be.within(expected.x - delta, expected.x + delta);
expect(this.obj.y).to
.be.within(expected.y - delta, expected.y + delta);
expect.Assertion.prototype.near = function (expected, delta) {
delta = delta || 1;
expect(this.obj.x).to
.be.within(expected.x - delta, expected.x + delta);
expect(this.obj.y).to
.be.within(expected.y - delta, expected.y + delta);
};

expect.Assertion.prototype.nearLatLng = function(expected, delta) {
delta = delta || 1e-4;
expect(this.obj.lat).to
.be.within(expected.lat - delta, expected.lat + delta);
expect(this.obj.lng).to
.be.within(expected.lng - delta, expected.lng + delta);
};
expect.Assertion.prototype.nearLatLng = function (expected, delta) {
delta = delta || 1e-4;
expect(this.obj.lat).to
.be.within(expected.lat - delta, expected.lat + delta);
expect(this.obj.lng).to
.be.within(expected.lng - delta, expected.lng + delta);
};
2 changes: 1 addition & 1 deletion spec/suites/control/Control.LayersSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("Control.Layers", function () {
spy = sinon.spy();

map.on('baselayerchange', spy)
.whenReady(function() {
.whenReady(function () {
happen.click(layers._baseLayersList.getElementsByTagName("input")[0]);

expect(spy.called).to.be.ok();
Expand Down
24 changes: 12 additions & 12 deletions spec/suites/core/ClassSpec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
describe("Class", function() {
describe("Class", function () {

describe("#extend", function() {
describe("#extend", function () {
var Klass,
constructor,
method;

beforeEach(function() {
beforeEach(function () {
constructor = sinon.spy();
method = sinon.spy();

Expand All @@ -19,7 +19,7 @@ describe("Class", function() {
});
});

it("creates a class with the given constructor & properties", function() {
it("creates a class with the given constructor & properties", function () {
var a = new Klass();

expect(constructor.called).to.be.ok();
Expand All @@ -30,7 +30,7 @@ describe("Class", function() {
expect(method.called).to.be.ok();
});

it("inherits parent classes' constructor & properties", function() {
it("inherits parent classes' constructor & properties", function () {
var Klass2 = Klass.extend({baz: 2});

var b = new Klass2();
Expand All @@ -46,28 +46,28 @@ describe("Class", function() {
expect(method.called).to.be.ok();
});

it("supports static properties", function() {
it("supports static properties", function () {
expect(Klass.bla).to.eql(1);
});

it("inherits parent static properties", function() {
it("inherits parent static properties", function () {
var Klass2 = Klass.extend({});

expect(Klass2.bla).to.eql(1);
});

it("overrides parent static properties", function() {
it("overrides parent static properties", function () {
var Klass2 = Klass.extend({statics: {bla: 2}});

expect(Klass2.bla).to.eql(2);
});

it("includes the given mixin", function() {
it("includes the given mixin", function () {
var a = new Klass();
expect(a.mixin).to.be.ok();
});

it("includes multiple mixins", function() {
it("includes multiple mixins", function () {
var Klass2 = L.Class.extend({
includes: [{mixin: true}, {mixin2: true}]
});
Expand All @@ -77,14 +77,14 @@ describe("Class", function() {
expect(a.mixin2).to.be.ok();
});

it("grants the ability to include the given mixin", function() {
it("grants the ability to include the given mixin", function () {
Klass.include({mixin2: true});

var a = new Klass();
expect(a.mixin2).to.be.ok();
});

it("merges options instead of replacing them", function() {
it("merges options instead of replacing them", function () {
var KlassWithOptions1 = L.Class.extend({
options: {
foo1: 1,
Expand Down
47 changes: 24 additions & 23 deletions spec/suites/core/EventsSpec.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
describe('Events', function() {
describe('Events', function () {
var Klass;

beforeEach(function() {
beforeEach(function () {
Klass = L.Class.extend({
includes: L.Mixin.Events
});
});

describe('#fireEvent', function() {
describe('#fireEvent', function () {

it('fires all listeners added through #addEventListener', function() {
it('fires all listeners added through #addEventListener', function () {
var obj = new Klass(),
spy1 = sinon.spy(),
spy2 = sinon.spy(),
spy3 = sinon.spy(),
spy4 = sinon.spy(),
spy5 = sinon.spy();
spy5 = sinon.spy(),
spy6 = sinon.spy();

obj.addEventListener('test', spy1);
Expand All @@ -42,7 +42,7 @@ describe('Events', function() {
expect(spy6.callCount).to.be(1);
});

it('provides event object to listeners and executes them in the right context', function() {
it('provides event object to listeners and executes them in the right context', function () {
var obj = new Klass(),
obj2 = new Klass(),
obj3 = new Klass(),
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('Events', function() {
obj4.fireEvent('test', {baz: 4});
});

it('calls no listeners removed through #removeEventListener', function() {
it('calls no listeners removed through #removeEventListener', function () {
var obj = new Klass(),
spy = sinon.spy(),
spy2 = sinon.spy(),
Expand Down Expand Up @@ -171,7 +171,7 @@ describe('Events', function() {
expect(spy2.called).to.be(true);
});

it('removes listeners with a stamp originally added without one', function() {
it('removes listeners with a stamp originally added without one', function () {
var obj = new Klass(),
spy1 = sinon.spy(),
spy2 = sinon.spy(),
Expand Down Expand Up @@ -252,24 +252,25 @@ describe('Events', function() {
//Add and remove a listener
obj.addEventListener('test', spy, foo2);
obj.removeEventListener('test', spy, foo2);

expect(obj.hasEventListeners('test')).to.be(false);
});

it('makes sure an event is not triggered if a listener is removed during dispatch',function() {
it('makes sure an event is not triggered if a listener is removed during dispatch', function () {
var obj = new Klass(),
spy = sinon.spy();
obj.addEventListener('test', function() { obj.removeEventListener('test',spy); });
obj.addEventListener('test', spy);
obj.fireEvent('test');

obj.addEventListener('test', function () { obj.removeEventListener('test', spy); });
obj.addEventListener('test', spy);
obj.fireEvent('test');

expect(spy.called).to.be(false);
});
});

describe('#on, #off & #fire', function() {
describe('#on, #off & #fire', function () {

it('works like #addEventListener && #removeEventListener', function() {
it('works like #addEventListener && #removeEventListener', function () {
var obj = new Klass(),
spy = sinon.spy();

Expand All @@ -284,7 +285,7 @@ describe('Events', function() {
expect(spy.callCount).to.be.lessThan(2);
});

it('does not override existing methods with the same name', function() {
it('does not override existing methods with the same name', function () {
var spy1 = sinon.spy(),
spy2 = sinon.spy(),
spy3 = sinon.spy();
Expand All @@ -309,10 +310,10 @@ describe('Events', function() {
});
});

describe("#clearEventListeners", function() {
it("clears all registered listeners on an object", function() {
describe("#clearEventListeners", function () {
it("clears all registered listeners on an object", function () {
var spy = sinon.spy(),
obj = new Klass()
obj = new Klass(),
otherObj = new Klass();

obj.on('test', spy, obj);
Expand All @@ -326,8 +327,8 @@ describe('Events', function() {
});
});

describe('#once', function() {
it('removes event listeners after first trigger', function() {
describe('#once', function () {
it('removes event listeners after first trigger', function () {
var obj = new Klass(),
spy = sinon.spy();

Expand All @@ -341,7 +342,7 @@ describe('Events', function() {
expect(spy.callCount).to.be.lessThan(2);
});

it('works with an object hash', function() {
it('works with an object hash', function () {
var obj = new Klass(),
spy = sinon.spy(),
otherSpy = sinon.spy();
Expand Down Expand Up @@ -376,7 +377,7 @@ describe('Events', function() {
expect(spy.called).to.be(false);
});

it('works if called from a context that doesnt implement #Events', function() {
it('works if called from a context that doesnt implement #Events', function () {
var obj = new Klass(),
spy = sinon.spy(),
foo = {};
Expand Down
10 changes: 5 additions & 5 deletions spec/suites/core/UtilSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,15 @@ describe('Util', function () {

it('throws when a template token is not given', function () {
expect(function () {
L.Util.template(tpl, {foo: 'bar'});
L.Util.template(undefined, {foo: 'bar'});
}).to.throwError();
});
});

describe('#isArray', function () {
expect(L.Util.isArray([1, 2, 3])).to.be.true;
expect(L.Util.isArray(new Array(1, 2, 3))).to.be.true;
expect(L.Util.isArray('blabla')).to.be.false;
expect(L.Util.isArray({0: 1, 1: 2})).to.be.false;
expect(L.Util.isArray([1, 2, 3])).to.be(true);
expect(L.Util.isArray(new Array(1, 2, 3))).to.be(true);
expect(L.Util.isArray('blabla')).to.be(false);
expect(L.Util.isArray({0: 1, 1: 2})).to.be(false);
});
});
Loading

0 comments on commit 91c039b

Please sign in to comment.