Remove goog.asserts.*
This pull requests replaces type check hint assertions with type casts, library sanity check assertions with conditional console.assert statements in debug mode, and runtime sanity checks with assertions that throw an ol.AssertionError with an error code for lookup outside the library.
This commit is contained in:
@@ -673,17 +673,14 @@ describe('ol.format.WFS', function() {
|
||||
[-12416429, 6604910]
|
||||
]]));
|
||||
var error = false;
|
||||
try {
|
||||
expect(function() {
|
||||
format.writeTransaction(null, [updateFeature], null, {
|
||||
featureNS: 'http://foo',
|
||||
featureType: 'FAULTS',
|
||||
featurePrefix: 'foo',
|
||||
gmlOptions: {srsName: 'EPSG:900913'}
|
||||
});
|
||||
} catch (e) {
|
||||
error = true;
|
||||
}
|
||||
expect(error).to.be(true);
|
||||
}).to.throwException();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -35,22 +35,24 @@ describe('ol.layer.VectorTile', function() {
|
||||
});
|
||||
|
||||
describe('constructor (options)', function() {
|
||||
var layer = new ol.layer.VectorTile({
|
||||
renderMode: 'vector',
|
||||
source: new ol.source.VectorTile({})
|
||||
});
|
||||
expect(layer.getRenderMode()).to.be('vector');
|
||||
layer = new ol.layer.VectorTile({
|
||||
renderMode: 'image',
|
||||
source: new ol.source.VectorTile({})
|
||||
});
|
||||
expect(layer.getRenderMode()).to.be('image');
|
||||
expect(function() {
|
||||
layer = new ol.layer.VectorTile({
|
||||
renderMode: 'foo',
|
||||
it('works with options', function() {
|
||||
var layer = new ol.layer.VectorTile({
|
||||
renderMode: 'vector',
|
||||
source: new ol.source.VectorTile({})
|
||||
});
|
||||
}).to.throwException();
|
||||
expect(layer.getRenderMode()).to.be('vector');
|
||||
layer = new ol.layer.VectorTile({
|
||||
renderMode: 'image',
|
||||
source: new ol.source.VectorTile({})
|
||||
});
|
||||
expect(layer.getRenderMode()).to.be('image');
|
||||
expect(function() {
|
||||
layer = new ol.layer.VectorTile({
|
||||
renderMode: 'foo',
|
||||
source: new ol.source.VectorTile({})
|
||||
});
|
||||
}).to.throwException();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -111,6 +111,12 @@ describe('ol.math.solveLinearSystem', function() {
|
||||
expect(result).to.be(null);
|
||||
});
|
||||
it('raises an exception when the matrix is malformed', function() {
|
||||
var origAssert = console.assert;
|
||||
console.assert = function(assertion, message) {
|
||||
if (!assertion) {
|
||||
throw new Error(message);
|
||||
}
|
||||
};
|
||||
expect(function() {
|
||||
ol.math.solveLinearSystem([
|
||||
[2, 1, 3, 1],
|
||||
@@ -126,6 +132,7 @@ describe('ol.math.solveLinearSystem', function() {
|
||||
[6, 8, 18, 5, 0]
|
||||
]);
|
||||
}).to.throwException();
|
||||
console.assert = origAssert;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
37
test/spec/ol/ol.test.js
Normal file
37
test/spec/ol/ol.test.js
Normal file
@@ -0,0 +1,37 @@
|
||||
goog.provide('ol.test');
|
||||
|
||||
describe('ol', function() {
|
||||
|
||||
describe('ol.assert', function() {
|
||||
it('throws an exception', function() {
|
||||
expect(function() {
|
||||
ol.assert(false, 42);
|
||||
}).to.throwException();
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.AssertionError', function() {
|
||||
it('generates a message', function() {
|
||||
var error = new ol.AssertionError(42);
|
||||
expect(error.message).to.be('Assertion failed. See /doc/errors.html#42 for details.');
|
||||
});
|
||||
it('generates a message with a versioned url', function() {
|
||||
var origVersion = ol.VERSION;
|
||||
ol.VERSION = 'foo';
|
||||
var error = new ol.AssertionError(42);
|
||||
expect(error.message).to.be('Assertion failed. See http://openlayers.org/en/foo/doc/errors.html#42 for details.');
|
||||
ol.VERSION = origVersion;
|
||||
});
|
||||
it('has an error code', function() {
|
||||
var error = new ol.AssertionError(42);
|
||||
expect(error.code).to.be(42);
|
||||
});
|
||||
it('has a name', function() {
|
||||
var error = new ol.AssertionError(42);
|
||||
expect(error.name).to.be('AssertionError');
|
||||
})
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol');
|
||||
@@ -9,11 +9,20 @@ describe('ol.structs.PriorityQueue', function() {
|
||||
|
||||
describe('when empty', function() {
|
||||
|
||||
var pq;
|
||||
var pq, origAssert;
|
||||
beforeEach(function() {
|
||||
origAssert = console.assert;
|
||||
console.assert = function(assertion, message) {
|
||||
if (!assertion) {
|
||||
throw new Error(message);
|
||||
}
|
||||
}
|
||||
pq = new ol.structs.PriorityQueue(
|
||||
identity, identity);
|
||||
});
|
||||
afterEach(function() {
|
||||
console.assert = origAssert;
|
||||
});
|
||||
|
||||
it('is valid', function() {
|
||||
expect(function() {
|
||||
|
||||
@@ -58,9 +58,11 @@ describe('ol.TileRange', function() {
|
||||
});
|
||||
|
||||
describe('with mixed z', function() {
|
||||
expect(function() {
|
||||
return new ol.TileRange.boundingTileRange([3, 1, 3], [4, 2, 0]);
|
||||
}).to.throwException();
|
||||
it('returns the expected TileRange', function() {
|
||||
expect(function() {
|
||||
return new ol.TileRange.boundingTileRange([3, 1, 3], [4, 2, 0]);
|
||||
}).to.throwException();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user