Test.Assert Class
The Assert object provides functions to test JavaScript values against known and expected results. Whenever a comparison (assertion) fails, an error is thrown.
Item Index
Methods
- _formatMessage static
- _getCount static
- _increment static
- _reset static
- areEqual static
- areNotEqual static
- areNotSame static
- areSame static
- fail static
- isArray static
- isBoolean static
- isFalse static
- isFunction static
- isInstanceOf static
- isNaN static
- isNotNaN static
- isNotNull static
- isNotUndefined static
- isNull static
- isNumber static
- isObject static
- isString static
- isTrue static
- isTypeOf static
- isUndefined static
- pass static
- throwsError static
Properties
Methods
_formatMessage
-
customMessage
-
defaultMessage
Formats a message so that it can contain the original assertion message in addition to the custom message.
Parameters:
Returns:
_getCount
()
protected
static
Returns the number of assertions that have been performed.
_increment
()
protected
static
Increments the number of assertions that have been performed.
_reset
()
protected
static
Resets the number of assertions that have been performed to 0.
areEqual
-
expected
-
actual
-
message
Asserts that a value is equal to another. This uses the double equals sign so type coercion may occur.
areNotEqual
-
unexpected
-
actual
-
message
Asserts that a value is not equal to another. This uses the double equals sign so type coercion may occur.
areNotSame
-
unexpected
-
actual
-
message
Asserts that a value is not the same as another. This uses the triple equals sign so no type coercion may occur.
areSame
-
expected
-
actual
-
message
Asserts that a value is the same as another. This uses the triple equals sign so no type coercion may occur.
fail
-
message
Forces an assertion error to occur.
Parameters:
-
message
String(Optional) The message to display with the failure.
isArray
-
actual
-
message
Asserts that a value is an array.
isBoolean
-
actual
-
message
Asserts that a value is a Boolean.
isFalse
-
actual
-
message
Asserts that a value is false. This uses the triple equals sign so no type coercion may occur.
isFunction
-
actual
-
message
Asserts that a value is a function.
isInstanceOf
-
expected
-
actual
-
message
Asserts that a value is an instance of a particular object. This may return incorrect results when comparing objects from one frame to constructors in another frame. For best results, don't use in a cross-frame manner.
isNaN
-
actual
-
message
Asserts that a value is not a number.
isNotNaN
-
actual
-
message
Asserts that a value is not the special NaN value.
isNotNull
-
actual
-
message
Asserts that a value is not null. This uses the triple equals sign so no type coercion may occur.
isNotUndefined
-
actual
-
message
Asserts that a value is not undefined. This uses the triple equals sign so no type coercion may occur.
isNull
-
actual
-
message
Asserts that a value is null. This uses the triple equals sign so no type coercion may occur.
isNumber
-
actual
-
message
Asserts that a value is a number.
isObject
-
actual
-
message
Asserts that a value is an object.
isString
-
actual
-
message
Asserts that a value is a string.
isTrue
-
actual
-
message
Asserts that a value is true. This uses the triple equals sign so no type coercion may occur.
isTypeOf
-
expectedType
-
actualValue
-
message
Asserts that a value is of a particular type.
isUndefined
-
actual
-
message
Asserts that a value is undefined. This uses the triple equals sign so no type coercion may occur.
pass
()
static
A marker that the test should pass.
throwsError
-
expectedError
-
method
-
message
Asserts that executing a particular method should throw an error of a specific type. This is a replacement for _should.error.
Parameters:
-
expectedError
String | Function | ObjectIf a string, this is the error message that the error must have; if a function, this is the constructor that should have been used to create the thrown error; if an object, this is an instance of a particular error type with a specific error message (both must match).
-
method
FunctionThe method to execute that should throw the error.
-
message
String(Optional) The message to display if the assertion fails.
Returns:
Properties
_asserts
Int
private
The number of assertions performed.