test: Added expect(spy).to.be.called() syntactic sugar

This commit is contained in:
Tobias Bieniek
2013-03-13 17:18:23 +01:00
parent 93577bd335
commit 47261124fc
5 changed files with 32 additions and 27 deletions

View File

@@ -80,7 +80,7 @@ describe('ol.collection', function() {
describe('on an empty collection', function() { describe('on an empty collection', function() {
it('does not call the callback', function() { it('does not call the callback', function() {
collection.forEach(cb); collection.forEach(cb);
expect(cb.called).to.not.be.ok(); expect(cb).to.not.be.called();
}); });
}); });
describe('on a non-empty collection', function() { describe('on a non-empty collection', function() {
@@ -116,7 +116,7 @@ describe('ol.collection', function() {
var cb = sinon.spy(); var cb = sinon.spy();
goog.events.listen(collection, ol.CollectionEventType.REMOVE, cb); goog.events.listen(collection, ol.CollectionEventType.REMOVE, cb);
expect(collection.remove(1)).to.eql(1); 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); expect(cb.lastCall.args[0].elem).to.eql(1);
}); });
it('does not remove more than one matching element', function() { it('does not remove more than one matching element', function() {
@@ -206,21 +206,21 @@ describe('ol.collection', function() {
describe('insertAt', function() { describe('insertAt', function() {
it('triggers length_changed event', function() { it('triggers length_changed event', function() {
collection.insertAt(2, 3); collection.insertAt(2, 3);
expect(cb.called).to.be.ok(); expect(cb).to.be.called();
}); });
}); });
describe('removeAt', function() { describe('removeAt', function() {
it('triggers length_changed event', function() { it('triggers length_changed event', function() {
collection.removeAt(0); collection.removeAt(0);
expect(cb.called).to.be.ok(); expect(cb).to.be.called();
}); });
}); });
describe('setAt', function() { describe('setAt', function() {
it('does not trigger length_changed event', function() { it('does not trigger length_changed event', function() {
collection.setAt(1, 1); 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() { it('can filter by geometry type using its GeometryType index', function() {
sinon.spy(geomFilter, 'applies'); sinon.spy(geomFilter, 'applies');
var lineStrings = layer.getFeatures(geomFilter); 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.length).to.eql(4);
expect(lineStrings).to.contain(features[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() { it('can filter by extent using its RTree', function() {
sinon.spy(extentFilter, 'applies'); sinon.spy(extentFilter, 'applies');
var subset = layer.getFeatures(extentFilter); 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.length).to.eql(4);
expect(subset).not.to.contain(features[7]); expect(subset).not.to.contain(features[7]);
}); });
@@ -78,8 +78,8 @@ describe('ol.layer.Vector', function() {
sinon.spy(filter2, 'applies'); sinon.spy(filter2, 'applies');
var subset1 = layer.getFeatures(filter1); var subset1 = layer.getFeatures(filter1);
var subset2 = layer.getFeatures(filter2); var subset2 = layer.getFeatures(filter2);
expect(filter1.applies.called).to.not.be.ok(); expect(filter1.applies).to.not.be.called();
expect(filter2.applies.called).to.not.be.ok(); expect(filter2.applies).to.not.be.called();
expect(subset1.length).to.eql(0); expect(subset1.length).to.eql(0);
expect(subset2.length).to.eql(0); expect(subset2.length).to.eql(0);
}); });
@@ -89,7 +89,7 @@ describe('ol.layer.Vector', function() {
ol.filter.LogicalOperator.OR); ol.filter.LogicalOperator.OR);
sinon.spy(filter, 'applies'); sinon.spy(filter, 'applies');
var subset = layer.getFeatures(filter); var subset = layer.getFeatures(filter);
expect(filter.applies.called).to.be.ok(); expect(filter.applies).to.be.called();
expect(subset.length).to.eql(8); 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 // confirm that the center is somewhere between origin and destination
// after a short delay // after a short delay
setTimeout(function() { setTimeout(function() {
expect(o.callback.called).to.be.ok(); expect(o.callback).to.be.called();
var loc = map.getView().getCenter(); var loc = map.getView().getCenter();
expect(loc.x).not.to.eql(origin.x); expect(loc.x).not.to.eql(origin.x);
expect(loc.y).not.to.eql(origin.y); expect(loc.y).not.to.eql(origin.y);

View File

@@ -116,17 +116,17 @@ describe('ol.Object', function() {
it('dispatches events', function() { it('dispatches events', function() {
o.notify('k'); o.notify('k');
expect(listener1.called).to.be.ok(); expect(listener1).to.be.called();
}); });
it('dispatches generic change events to bound objects', function() { it('dispatches generic change events to bound objects', function() {
o.notify('k'); o.notify('k');
expect(listener2.called).to.be.ok(); expect(listener2).to.be.called();
}); });
it('dispatches events to bound objects', function() { it('dispatches events to bound objects', function() {
o.notify('k'); 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() { it('dispatches events to object', function() {
o.set('k', 1); o.set('k', 1);
expect(listener1.called).to.be.ok(); expect(listener1).to.be.called();
expect(o.getKeys()).to.eql(['k']); expect(o.getKeys()).to.eql(['k']);
expect(o2.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() { it('dispatches generic change events to object', function() {
o.set('k', 1); o.set('k', 1);
expect(listener2.called).to.be.ok(); expect(listener2).to.be.called();
}); });
it('dispatches events to bound object', function() { it('dispatches events to bound object', function() {
o.set('k', 1); o.set('k', 1);
expect(listener3.called).to.be.ok(); expect(listener3).to.be.called();
}); });
it('dispatches events to object bound to', function() { it('dispatches events to object bound to', function() {
o2.set('k', 2); o2.set('k', 2);
expect(listener1.called).to.be.ok(); expect(listener1).to.be.called();
expect(o.getKeys()).to.eql(['k']); expect(o.getKeys()).to.eql(['k']);
expect(o2.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() { it('dispatches generic change events to object bound to', function() {
o2.set('k', 2); 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(o.get('k2')).to.be(undefined);
expect(o2.get('k2')).to.eql(1); expect(o2.get('k2')).to.eql(1);
expect(o2.get('k1')).to.be(undefined); expect(o2.get('k1')).to.be(undefined);
expect(listener1.called).to.be.ok(); expect(listener1).to.be.called();
expect(listener2.called).to.be.ok(); expect(listener2).to.be.called();
expect(o.getKeys()).to.eql(['k1']); expect(o.getKeys()).to.eql(['k1']);
expect(o2.getKeys()).to.eql(['k2']); expect(o2.getKeys()).to.eql(['k2']);
@@ -392,7 +392,7 @@ describe('ol.Object', function() {
it('does not call the setter', function() { it('does not call the setter', function() {
o.set('x', 1); o.set('x', 1);
expect(o.get('x')).to.eql(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']); expect(o.getKeys()).to.eql(['x']);
}); });
@@ -403,7 +403,7 @@ describe('ol.Object', function() {
var o2 = new ol.Object(); var o2 = new ol.Object();
o2.bindTo('x', o); o2.bindTo('x', o);
o2.set('x', 1); 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.get('x')).to.eql(1);
expect(o.getKeys()).to.eql(['x']); expect(o.getKeys()).to.eql(['x']);
@@ -423,7 +423,7 @@ describe('ol.Object', function() {
describe('without bind', function() { describe('without bind', function() {
it('does not call the getter', function() { it('does not call the getter', function() {
expect(o.get('x')).to.be(undefined); 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(); var o2 = new ol.Object();
o2.bindTo('x', o); o2.bindTo('x', o);
expect(o2.get('x')).to.eql(1); 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(o.getKeys()).to.eql([]);
expect(o2.getKeys()).to.eql(['x']); expect(o2.getKeys()).to.eql(['x']);
@@ -467,8 +467,8 @@ describe('ol.Object', function() {
it('dispatches the expected event', function() { it('dispatches the expected event', function() {
o.set('K', 1); o.set('K', 1);
expect(listener1.called).to.be.ok(); expect(listener1).to.be.called();
expect(listener2.called).to.not.be.ok(); expect(listener2).to.not.be.called();
expect(o.getKeys()).to.eql(['K']); expect(o.getKeys()).to.eql(['K']);
}); });

View File

@@ -29,6 +29,11 @@ expect.Assertion.prototype.intersectWith = function(other) {
}; };
expect.Assertion.prototype.called = function() {
return this.obj.called;
};
// helper functions for async testing // helper functions for async testing
(function(global) { (function(global) {