Merge pull request #362 from Turbo87/test-improvements

Test improvements
This commit is contained in:
Éric Lemoine
2013-03-13 10:18:00 -07:00
6 changed files with 36 additions and 30 deletions

View File

@@ -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 File

@@ -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 File

@@ -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 File

@@ -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 File

@@ -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 File

@@ -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) {