Permalink
Browse files

Converted "vector" branch unit tests to mocha, expect.js and sinon

  • Loading branch information...
1 parent 8273d88 commit d5d8afc858ae017f7b5ea1c6ed64cc1b61660e63 @Turbo87 committed Mar 13, 2013
@@ -5,7 +5,7 @@ describe('ol.Expression', function() {
describe('constructor', function() {
it('creates an expression', function() {
var exp = new ol.Expression('foo');
- expect(exp).toBeA(ol.Expression);
+ expect(exp).to.be.a(ol.Expression);
});
});
@@ -31,7 +31,7 @@ describe('ol.Expression', function() {
for (var i = 0, ii = cases.length; i < ii; ++i) {
c = cases[i];
exp = new ol.Expression(c.source);
- expect(exp.evaluate()).toBe(c.result);
+ expect(exp.evaluate()).to.be(c.result);
}
});
@@ -41,8 +41,8 @@ describe('ol.Expression', function() {
};
var exp = new ol.Expression('this.works ? "yes" : "no"');
- expect(exp.evaluate(new Thing())).toBe('yes');
- expect(exp.evaluate({})).toBe('no');
+ expect(exp.evaluate(new Thing())).to.be('yes');
+ expect(exp.evaluate({})).to.be('no');
});
it('accepts an optional scope argument', function() {
@@ -57,18 +57,18 @@ describe('ol.Expression', function() {
// access two members in the scope
exp = new ol.Expression('greeting + punctuation');
- expect(exp.evaluate({}, scope)).toBe('hello world!');
+ expect(exp.evaluate({}, scope)).to.be('hello world!');
// call a function in the scope
exp = new ol.Expression(
'pick([10, 42, "chicken"], 2) + Math.floor(Math.PI)');
- expect(exp.evaluate({}, scope)).toBe('chicken3');
+ expect(exp.evaluate({}, scope)).to.be('chicken3');
});
it('throws on error', function() {
var exp = new ol.Expression('@*)$(&');
- expect(function() {exp.evaluate()}).toThrow();
+ expect(function() {exp.evaluate()}).to.throwException();
});
});
@@ -6,14 +6,14 @@ describe('ol.Feature', function() {
it('creates a new feature', function() {
var feature = new ol.Feature();
- expect(feature).toBeA(ol.Feature);
+ expect(feature).to.be.a(ol.Feature);
});
it('takes attribute values', function() {
var feature = new ol.Feature({
foo: 'bar'
});
- expect(feature.get('foo')).toBe('bar');
+ expect(feature.get('foo')).to.be('bar');
});
it('will set the default geometry', function() {
@@ -22,8 +22,8 @@ describe('ol.Feature', function() {
foo: 'bar'
});
var geometry = feature.getGeometry();
- expect(geometry).toBeA(ol.geom.Point);
- expect(feature.get('loc')).toBe(geometry);
+ expect(geometry).to.be.a(ol.geom.Point);
+ expect(feature.get('loc')).to.be(geometry);
});
});
@@ -35,19 +35,19 @@ describe('ol.Feature', function() {
a: 'first',
b: 'second'
});
- expect(feature.get('a')).toBe('first');
- expect(feature.get('b')).toBe('second');
+ expect(feature.get('a')).to.be('first');
+ expect(feature.get('b')).to.be('second');
});
it('returns undefined for unset attributes', function() {
var feature = new ol.Feature();
- expect(feature.get('a')).toBeUndefined();
+ expect(feature.get('a')).to.be(undefined);
});
it('returns values set by set', function() {
var feature = new ol.Feature();
feature.set('a', 'b');
- expect(feature.get('a')).toBe('b');
+ expect(feature.get('a')).to.be('b');
});
});
@@ -65,11 +65,11 @@ describe('ol.Feature', function() {
var attributes = feature.getAttributes();
var keys = goog.object.getKeys(attributes);
- expect(keys.sort()).toEqual(['foo', 'loc', 'ten']);
+ expect(keys.sort()).to.eql(['foo', 'loc', 'ten']);
- expect(attributes.foo).toBe('bar');
- expect(attributes.loc).toBe(point);
- expect(attributes.ten).toBe(10);
+ expect(attributes.foo).to.be('bar');
+ expect(attributes.loc).to.be(point);
+ expect(attributes.ten).to.be(10);
});
});
@@ -81,33 +81,33 @@ describe('ol.Feature', function() {
it('returns null for no geometry', function() {
var feature = new ol.Feature();
- expect(feature.getGeometry()).toBeNull();
+ expect(feature.getGeometry()).to.be(null);
});
it('gets the geometry set at construction', function() {
var feature = new ol.Feature({
geom: point
});
- expect(feature.getGeometry()).toBe(point);
+ expect(feature.getGeometry()).to.be(point);
});
it('gets any geometry set by setGeometry', function() {
var feature = new ol.Feature();
feature.setGeometry(point);
- expect(feature.getGeometry()).toBe(point);
+ expect(feature.getGeometry()).to.be(point);
var point2 = new ol.geom.Point([1, 2]);
feature.setGeometry(point2);
- expect(feature.getGeometry()).toBe(point2);
+ expect(feature.getGeometry()).to.be(point2);
});
it('gets the first geometry set by set', function() {
var feature = new ol.Feature();
feature.set('foo', point);
- expect(feature.getGeometry()).toBe(point);
+ expect(feature.getGeometry()).to.be(point);
feature.set('bar', new ol.geom.Point([1, 2]));
- expect(feature.getGeometry()).toBe(point);
+ expect(feature.getGeometry()).to.be(point);
});
});
@@ -120,7 +120,7 @@ describe('ol.Feature', function() {
b: 'second'
});
feature.set('a', 'new');
- expect(feature.get('a')).toBe('new');
+ expect(feature.get('a')).to.be('new');
});
it('can be used to set the geometry', function() {
@@ -129,23 +129,23 @@ describe('ol.Feature', function() {
loc: new ol.geom.Point([1, 2])
});
feature.set('loc', point);
- expect(feature.get('loc')).toBe(point);
- expect(feature.getGeometry()).toBe(point);
+ expect(feature.get('loc')).to.be(point);
+ expect(feature.getGeometry()).to.be(point);
});
it('can be used to set attributes with arbitrary names', function() {
var feature = new ol.Feature();
feature.set('toString', 'string');
- expect(feature.get('toString')).toBe('string');
- expect(typeof feature.toString).toBe('function');
+ expect(feature.get('toString')).to.be('string');
+ expect(typeof feature.toString).to.be('function');
feature.set('getGeometry', 'x');
- expect(feature.get('getGeometry')).toBe('x');
+ expect(feature.get('getGeometry')).to.be('x');
feature.set('geom', new ol.geom.Point([1, 2]));
- expect(feature.getGeometry()).toBeA(ol.geom.Point);
+ expect(feature.getGeometry()).to.be.a(ol.geom.Point);
});
@@ -158,37 +158,37 @@ describe('ol.Feature', function() {
it('sets the default geometry', function() {
var feature = new ol.Feature();
feature.setGeometry(point);
- expect(feature.get(ol.Feature.DEFAULT_GEOMETRY)).toBe(point);
+ expect(feature.get(ol.Feature.DEFAULT_GEOMETRY)).to.be(point);
});
it('replaces previous default geometry', function() {
var feature = new ol.Feature({
geom: point
});
- expect(feature.getGeometry()).toBe(point);
+ expect(feature.getGeometry()).to.be(point);
var point2 = new ol.geom.Point([1, 2]);
feature.setGeometry(point2);
- expect(feature.getGeometry()).toBe(point2);
+ expect(feature.getGeometry()).to.be(point2);
});
it('gets any geometry set by setGeometry', function() {
var feature = new ol.Feature();
feature.setGeometry(point);
- expect(feature.getGeometry()).toBe(point);
+ expect(feature.getGeometry()).to.be(point);
var point2 = new ol.geom.Point([1, 2]);
feature.setGeometry(point2);
- expect(feature.getGeometry()).toBe(point2);
+ expect(feature.getGeometry()).to.be(point2);
});
it('gets the first geometry set by set', function() {
var feature = new ol.Feature();
feature.set('foo', point);
- expect(feature.getGeometry()).toBe(point);
+ expect(feature.getGeometry()).to.be(point);
feature.set('bar', new ol.geom.Point([1, 2]));
- expect(feature.getGeometry()).toBe(point);
+ expect(feature.getGeometry()).to.be(point);
});
});
@@ -13,7 +13,7 @@ describe('ol.filter.Extent', function() {
describe('#getExtent()', function() {
it('returns the configured extent', function() {
- expect(filter.getExtent()).toBe(extent);
+ expect(filter.getExtent()).to.be(extent);
});
});
@@ -22,9 +22,9 @@ describe('ol.filter.Extent', function() {
it('returns true if a feature intersects, false if not', function() {
expect(filter.applies(new ol.Feature({g: new ol.geom.Point([44, 89])})))
- .toBe(true);
+ .to.be(true);
expect(filter.applies(new ol.Feature({g: new ol.geom.Point([46, 91])})))
- .toBe(false);
+ .to.be(false);
});
});
@@ -6,41 +6,41 @@ describe('ol.filter.Geometry', function() {
describe('constructor', function() {
it('creates a new filter', function() {
var filter = new ol.filter.Geometry(ol.filter.GeometryType.POINT);
- expect(filter).toBeA(ol.filter.Geometry);
+ expect(filter).to.be.a(ol.filter.Geometry);
});
});
describe('#getType()', function() {
it('works for point', function() {
var filter = new ol.filter.Geometry(ol.filter.GeometryType.POINT);
- expect(filter.getType()).toBe(ol.filter.GeometryType.POINT);
+ expect(filter.getType()).to.be(ol.filter.GeometryType.POINT);
});
it('works for linestring', function() {
var filter = new ol.filter.Geometry(ol.filter.GeometryType.LINESTRING);
- expect(filter.getType()).toBe(ol.filter.GeometryType.LINESTRING);
+ expect(filter.getType()).to.be(ol.filter.GeometryType.LINESTRING);
});
it('works for polygon', function() {
var filter = new ol.filter.Geometry(ol.filter.GeometryType.POLYGON);
- expect(filter.getType()).toBe(ol.filter.GeometryType.POLYGON);
+ expect(filter.getType()).to.be(ol.filter.GeometryType.POLYGON);
});
it('works for multi-point', function() {
var filter = new ol.filter.Geometry(ol.filter.GeometryType.MULTIPOINT);
- expect(filter.getType()).toBe(ol.filter.GeometryType.MULTIPOINT);
+ expect(filter.getType()).to.be(ol.filter.GeometryType.MULTIPOINT);
});
it('works for multi-linestring', function() {
var filter = new ol.filter.Geometry(
ol.filter.GeometryType.MULTILINESTRING);
- expect(filter.getType()).toBe(ol.filter.GeometryType.MULTILINESTRING);
+ expect(filter.getType()).to.be(ol.filter.GeometryType.MULTILINESTRING);
});
it('works for multi-polygon', function() {
var filter = new ol.filter.Geometry(ol.filter.GeometryType.MULTIPOLYGON);
- expect(filter.getType()).toBe(ol.filter.GeometryType.MULTIPOLYGON);
+ expect(filter.getType()).to.be(ol.filter.GeometryType.MULTIPOLYGON);
});
});
@@ -14,8 +14,8 @@ describe('ol.geom.GeometryCollection', function() {
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
var multi = new ol.geom.GeometryCollection([point, line, poly]);
- expect(multi).toBeA(ol.geom.GeometryCollection);
- expect(multi).toBeA(ol.geom.Geometry);
+ expect(multi).to.be.a(ol.geom.GeometryCollection);
+ expect(multi).to.be.a(ol.geom.Geometry);
});
});
@@ -28,10 +28,10 @@ describe('ol.geom.GeometryCollection', function() {
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
var multi = new ol.geom.GeometryCollection([point, line, poly]);
- expect(multi.components.length).toBe(3);
- expect(multi.components[0]).toBeA(ol.geom.Point);
- expect(multi.components[1]).toBeA(ol.geom.LineString);
- expect(multi.components[2]).toBeA(ol.geom.Polygon);
+ expect(multi.components.length).to.be(3);
+ expect(multi.components[0]).to.be.a(ol.geom.Point);
+ expect(multi.components[1]).to.be.a(ol.geom.LineString);
+ expect(multi.components[2]).to.be.a(ol.geom.Polygon);
});
});
@@ -43,14 +43,14 @@ describe('ol.geom.GeometryCollection', function() {
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
var multi = new ol.geom.GeometryCollection([point, line, poly]);
- expect(multi.dimension).toBe(2);
+ expect(multi.dimension).to.be(2);
});
it('can be 3', function() {
var multi = new ol.geom.GeometryCollection([
new ol.geom.Point([30, 40, 50])
]);
- expect(multi.dimension).toBe(3);
+ expect(multi.dimension).to.be(3);
});
});
@@ -62,10 +62,10 @@ describe('ol.geom.GeometryCollection', function() {
var line = new ol.geom.LineString([[1, 20], [30, 40]]);
var multi = new ol.geom.GeometryCollection([point, line]);
var bounds = multi.getBounds();
- expect(bounds.minX).toBe(1);
- expect(bounds.minY).toBe(2);
- expect(bounds.maxX).toBe(30);
- expect(bounds.maxY).toBe(40);
+ expect(bounds.minX).to.be(1);
+ expect(bounds.minY).to.be(2);
+ expect(bounds.maxX).to.be(30);
+ expect(bounds.maxY).to.be(40);
});
});
Oops, something went wrong.

0 comments on commit d5d8afc

Please sign in to comment.