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.
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
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');
|