The goog.asserts Namespace

The goog.asserts.AssertionError Class

Error object for failed assertions. … more

.ENABLE_ASSERTS

.assert(condition, opt_message, var_args)

Checks if the condition evaluates to true if goog.asserts.ENABLE_ASSERTS is true.

condition {*}
The condition to check.
opt_message {string=}
Error message in case of failure.
var_args {...*}
The items to substitute into the failure message.
returns {*}
The value of the condition.
@throws
{goog.asserts.AssertionError} When the condition evaluates to false.

.assertArray(value, opt_message, var_args)

Checks if the value is an Array if goog.asserts.ENABLE_ASSERTS is true.

value {*}
The value to check.
opt_message {string=}
Error message in case of failure.
var_args {...*}
The items to substitute into the failure message.
returns {!Array}
The value, guaranteed to be a non-null array.
@throws
{goog.asserts.AssertionError} When the value is not an array.

.assertBoolean(value, opt_message, var_args)

Checks if the value is a boolean if goog.asserts.ENABLE_ASSERTS is true.

value {*}
The value to check.
opt_message {string=}
Error message in case of failure.
var_args {...*}
The items to substitute into the failure message.
returns {boolean}
The value, guaranteed to be a boolean when asserts are enabled.
@throws
{goog.asserts.AssertionError} When the value is not a boolean.

.assertFunction(value, opt_message, var_args)

Checks if the value is a function if goog.asserts.ENABLE_ASSERTS is true.

value {*}
The value to check.
opt_message {string=}
Error message in case of failure.
var_args {...*}
The items to substitute into the failure message.
returns {!Function}
The value, guaranteed to be a function when asserts enabled.
@throws
{goog.asserts.AssertionError} When the value is not a function.

.assertInstanceof(value, type, opt_message, var_args)

Checks if the value is an instance of the user-defined type if goog.asserts.ENABLE_ASSERTS is true. The compiler may tighten the type returned by this function.

value {*}
The value to check.
type {!Function}
A user-defined constructor.
opt_message {string=}
Error message in case of failure.
var_args {...*}
The items to substitute into the failure message.
returns {!Object}
@throws
{goog.asserts.AssertionError} When the value is not an instance of type.

.assertNumber(value, opt_message, var_args)

Checks if the value is a number if goog.asserts.ENABLE_ASSERTS is true.

value {*}
The value to check.
opt_message {string=}
Error message in case of failure.
var_args {...*}
The items to substitute into the failure message.
returns {number}
The value, guaranteed to be a number when asserts enabled.
@throws
{goog.asserts.AssertionError} When the value is not a number.

.assertObject(value, opt_message, var_args)

Checks if the value is an Object if goog.asserts.ENABLE_ASSERTS is true.

value {*}
The value to check.
opt_message {string=}
Error message in case of failure.
var_args {...*}
The items to substitute into the failure message.
returns {!Object}
The value, guaranteed to be a non-null object.
@throws
{goog.asserts.AssertionError} When the value is not an object.

.assertString(value, opt_message, var_args)

Checks if the value is a string if goog.asserts.ENABLE_ASSERTS is true.

value {*}
The value to check.
opt_message {string=}
Error message in case of failure.
var_args {...*}
The items to substitute into the failure message.
returns {string}
The value, guaranteed to be a string when asserts enabled.
@throws
{goog.asserts.AssertionError} When the value is not a string.

.fail(opt_message, var_args)

Fails if goog.asserts.ENABLE_ASSERTS is true. This function is useful in case when we want to add a check in the unreachable area like switch-case statement:

  switch(type) {
    case FOO: doSomething(); break;
    case BAR: doSomethingElse(); break;
    default: goog.assert.fail('Unrecognized type: ' + type);
      // We have only 2 types - "default:" section is unreachable code.
  }
 
opt_message {string=}
Error message in case of failure.
var_args {...*}
The items to substitute into the failure message.
@throws
{goog.asserts.AssertionError} Failure.