Skip to content

Loading…

Test improvements #362

Merged
merged 2 commits into from

2 participants

@Turbo87

Fixes #358 (diff) and adds syntactic sugar for the sinon spies.

@elemoine
OpenLayers member

Looks good. To be merged when Travis build status is known. Thanks.

@Turbo87 we try to use no more than 50 chars for the first line of commit messages, starting with a capital letter and not using punctuation (no final point). If we need to provide more information and be more verbose we use another paragraph. See CONTRIBUTING.md, which may miss some information. Thanks.

@elemoine elemoine merged commit ac86cc1 into openlayers:master

1 check passed

Details default The Travis build passed
@Turbo87 Turbo87 deleted the Turbo87:test-improvements branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
10 test/spec/ol/collection.test.js
@@ -80,7 +80,7 @@ describe('ol.collection', function() {
describe('on an empty collection', function() {
it('does not call the callback', function() {
collection.forEach(cb);
- expect(cb.called).to.not.be.ok();
+ expect(cb).to.not.be.called();
});
});
describe('on a non-empty collection', function() {
@@ -116,7 +116,7 @@ describe('ol.collection', function() {
var cb = sinon.spy();
goog.events.listen(collection, ol.CollectionEventType.REMOVE, cb);
expect(collection.remove(1)).to.eql(1);
- expect(cb.called).to.be.ok();
+ expect(cb).to.be.called();
expect(cb.lastCall.args[0].elem).to.eql(1);
});
it('does not remove more than one matching element', function() {
@@ -206,21 +206,21 @@ describe('ol.collection', function() {
describe('insertAt', function() {
it('triggers length_changed event', function() {
collection.insertAt(2, 3);
- expect(cb.called).to.be.ok();
+ expect(cb).to.be.called();
});
});
describe('removeAt', function() {
it('triggers length_changed event', function() {
collection.removeAt(0);
- expect(cb.called).to.be.ok();
+ expect(cb).to.be.called();
});
});
describe('setAt', function() {
it('does not trigger length_changed event', function() {
collection.setAt(1, 1);
- expect(cb.called).to.not.be.ok();
+ expect(cb).to.not.be.called();
});
});
});
View
10 test/spec/ol/layer/vectorlayer.test.js
@@ -56,7 +56,7 @@ describe('ol.layer.Vector', function() {
it('can filter by geometry type using its GeometryType index', function() {
sinon.spy(geomFilter, 'applies');
var lineStrings = layer.getFeatures(geomFilter);
- expect(geomFilter.applies.called).to.not.be.ok();
+ expect(geomFilter.applies).to.not.be.called();
expect(lineStrings.length).to.eql(4);
expect(lineStrings).to.contain(features[4]);
});
@@ -64,7 +64,7 @@ describe('ol.layer.Vector', function() {
it('can filter by extent using its RTree', function() {
sinon.spy(extentFilter, 'applies');
var subset = layer.getFeatures(extentFilter);
- expect(extentFilter.applies.called).to.not.be.ok();
+ expect(extentFilter.applies).to.not.be.called();
expect(subset.length).to.eql(4);
expect(subset).not.to.contain(features[7]);
});
@@ -78,8 +78,8 @@ describe('ol.layer.Vector', function() {
sinon.spy(filter2, 'applies');
var subset1 = layer.getFeatures(filter1);
var subset2 = layer.getFeatures(filter2);
- expect(filter1.applies.called).to.not.be.ok();
- expect(filter2.applies.called).to.not.be.ok();
+ expect(filter1.applies).to.not.be.called();
+ expect(filter2.applies).to.not.be.called();
expect(subset1.length).to.eql(0);
expect(subset2.length).to.eql(0);
});
@@ -89,7 +89,7 @@ describe('ol.layer.Vector', function() {
ol.filter.LogicalOperator.OR);
sinon.spy(filter, 'applies');
var subset = layer.getFeatures(filter);
- expect(filter.applies.called).to.be.ok();
+ expect(filter.applies).to.be.called();
expect(subset.length).to.eql(8);
});
View
2 test/spec/ol/map.test.js
@@ -198,7 +198,7 @@ describe('ol.Map', function() {
// confirm that the center is somewhere between origin and destination
// after a short delay
setTimeout(function() {
- expect(o.callback.called).to.be.ok();
+ expect(o.callback).to.be.called();
var loc = map.getView().getCenter();
expect(loc.x).not.to.eql(origin.x);
expect(loc.y).not.to.eql(origin.y);
View
32 test/spec/ol/object.test.js
@@ -116,17 +116,17 @@ describe('ol.Object', function() {
it('dispatches events', function() {
o.notify('k');
- expect(listener1.called).to.be.ok();
+ expect(listener1).to.be.called();
});
it('dispatches generic change events to bound objects', function() {
o.notify('k');
- expect(listener2.called).to.be.ok();
+ expect(listener2).to.be.called();
});
it('dispatches events to bound objects', function() {
o.notify('k');
- expect(listener3.called).to.be.ok();
+ expect(listener3).to.be.called();
});
});
@@ -149,7 +149,7 @@ describe('ol.Object', function() {
it('dispatches events to object', function() {
o.set('k', 1);
- expect(listener1.called).to.be.ok();
+ expect(listener1).to.be.called();
expect(o.getKeys()).to.eql(['k']);
expect(o2.getKeys()).to.eql(['k']);
@@ -157,17 +157,17 @@ describe('ol.Object', function() {
it('dispatches generic change events to object', function() {
o.set('k', 1);
- expect(listener2.called).to.be.ok();
+ expect(listener2).to.be.called();
});
it('dispatches events to bound object', function() {
o.set('k', 1);
- expect(listener3.called).to.be.ok();
+ expect(listener3).to.be.called();
});
it('dispatches events to object bound to', function() {
o2.set('k', 2);
- expect(listener1.called).to.be.ok();
+ expect(listener1).to.be.called();
expect(o.getKeys()).to.eql(['k']);
expect(o2.getKeys()).to.eql(['k']);
@@ -175,7 +175,7 @@ describe('ol.Object', function() {
it('dispatches generic change events to object bound to', function() {
o2.set('k', 2);
- expect(listener2.called).to.be.ok();
+ expect(listener2).to.be.called();
});
});
@@ -300,8 +300,8 @@ describe('ol.Object', function() {
expect(o.get('k2')).to.be(undefined);
expect(o2.get('k2')).to.eql(1);
expect(o2.get('k1')).to.be(undefined);
- expect(listener1.called).to.be.ok();
- expect(listener2.called).to.be.ok();
+ expect(listener1).to.be.called();
+ expect(listener2).to.be.called();
expect(o.getKeys()).to.eql(['k1']);
expect(o2.getKeys()).to.eql(['k2']);
@@ -392,7 +392,7 @@ describe('ol.Object', function() {
it('does not call the setter', function() {
o.set('x', 1);
expect(o.get('x')).to.eql(1);
- expect(o.setX.called).to.not.be.ok();
+ expect(o.setX).to.not.be.called();
expect(o.getKeys()).to.eql(['x']);
});
@@ -403,7 +403,7 @@ describe('ol.Object', function() {
var o2 = new ol.Object();
o2.bindTo('x', o);
o2.set('x', 1);
- expect(o.setX.called).to.be.ok();
+ expect(o.setX).to.be.called();
expect(o.get('x')).to.eql(1);
expect(o.getKeys()).to.eql(['x']);
@@ -423,7 +423,7 @@ describe('ol.Object', function() {
describe('without bind', function() {
it('does not call the getter', function() {
expect(o.get('x')).to.be(undefined);
- expect(o.getX.called).to.not.be.ok();
+ expect(o.getX).to.not.be.called();
});
});
@@ -432,7 +432,7 @@ describe('ol.Object', function() {
var o2 = new ol.Object();
o2.bindTo('x', o);
expect(o2.get('x')).to.eql(1);
- expect(o.getX.called).to.be.ok();
+ expect(o.getX).to.be.called();
expect(o.getKeys()).to.eql([]);
expect(o2.getKeys()).to.eql(['x']);
@@ -467,8 +467,8 @@ describe('ol.Object', function() {
it('dispatches the expected event', function() {
o.set('K', 1);
- expect(listener1.called).to.be.ok();
- expect(listener2.called).to.not.be.ok();
+ expect(listener1).to.be.called();
+ expect(listener2).to.not.be.called();
expect(o.getKeys()).to.eql(['K']);
});
View
3 test/spec/ol/rectangle.test.js
@@ -17,9 +17,6 @@ describe('ol.Rectangle', function() {
beforeEach(function() {
rectangle1 = new ol.Rectangle(50, 50, 100, 100);
- expect.Assertion.prototype.intersectWith = function(other) {
- return this.obj.intersects(other);
- };
});
it('returns the expected value', function() {
View
9 test/test-extensions.js
@@ -24,6 +24,15 @@ expect.Assertion.prototype.roughlyEqual = function(other, tol) {
};
+expect.Assertion.prototype.intersectWith = function(other) {
+ return this.obj.intersects(other);
+};
+
+
+expect.Assertion.prototype.called = function() {
+ return this.obj.called;
+};
+
// helper functions for async testing
(function(global) {
Something went wrong with that request. Please try again.