asserts

Classes

goog.asserts.AssertionError
Error object for failed assertions.

Public Protected Private

Global Functions

goog.asserts.assert(conditionopt_messagevar_args) T
Checks if the condition evaluates to true if goog.asserts.ENABLE_ASSERTS is true.
Arguments:
condition : T
The condition to check.
opt_message : string=
Error message in case of failure.
var_args : ...*
The items to substitute into the failure message.
Returns: T  The value of the condition.
code »
goog.asserts.assertArray(valueopt_messagevar_args) !Array
Checks if the value is an Array if goog.asserts.ENABLE_ASSERTS is true.
Arguments:
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.
code »
goog.asserts.assertBoolean(valueopt_messagevar_args) boolean
Checks if the value is a boolean if goog.asserts.ENABLE_ASSERTS is true.
Arguments:
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.
code »
goog.asserts.assertElement(valueopt_messagevar_args) !Element
Checks if the value is a DOM Element if goog.asserts.ENABLE_ASSERTS is true.
Arguments:
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: !Element  The value, likely to be a DOM Element when asserts are enabled.
code »
goog.asserts.assertFunction(valueopt_messagevar_args) !Function
Checks if the value is a function if goog.asserts.ENABLE_ASSERTS is true.
Arguments:
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.
code »
goog.asserts.assertInstanceof(valuetypeopt_messagevar_args) !T
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.
Arguments:
value : *
The value to check.
type : function(new: T, ...)
A user-defined constructor.
opt_message : string=
Error message in case of failure.
var_args : ...*
The items to substitute into the failure message.
Returns: !T  No description.
code »
goog.asserts.assertNumber(valueopt_messagevar_args) number
Checks if the value is a number if goog.asserts.ENABLE_ASSERTS is true.
Arguments:
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.
code »
goog.asserts.assertObject(valueopt_messagevar_args) !Object
Checks if the value is an Object if goog.asserts.ENABLE_ASSERTS is true.
Arguments:
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.
code »
goog.asserts.assertObjectPrototypeIsIntact()
Checks that no enumerable keys are present in Object.prototype. Such keys would break most code that use for (var ... in ...) loops.
code »
goog.asserts.assertString(valueopt_messagevar_args) string
Checks if the value is a string if goog.asserts.ENABLE_ASSERTS is true.
Arguments:
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.
code »
goog.asserts.doAssertFailure_(defaultMessagedefaultArgsgivenMessagegivenArgs)
Throws an exception with the given message and "Assertion failed" prefixed onto it.
Arguments:
defaultMessage : string
The message to use if givenMessage is empty.
defaultArgs : Array.<*>
The substitution arguments for defaultMessage.
givenMessage : string | undefined
Message supplied by the caller.
givenArgs : Array.<*>
The substitution arguments for givenMessage.
code »
goog.asserts.fail(opt_messagevar_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.
 }
Arguments:
opt_message : string=
Error message in case of failure.
var_args : ...*
The items to substitute into the failure message.
code »

Global Properties

goog.asserts.ENABLE_ASSERTS :
No description.
Code »

Package asserts

Package Reference