#

API Docs for: 3.10.3
Show: Inherited Protected Private Deprecated

# Test.Assert Class

Defined in: `test/js/Assert.js:2`
Module: test

The Assert object provides functions to test JavaScript values against known and expected results. Whenever a comparison (assertion) fails, an error is thrown.

- Index
- Methods
- Properties

## 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

- _asserts

## Methods

### `_formatMessage`

(

- `customMessage`
- `defaultMessage`

)
String protected static

Defined in `test/js/Assert.js:25`

Formats a message so that it can contain the original assertion message in addition to the custom message.

#### Parameters:

- `customMessage` String

  The message passed in by the developer.

- `defaultMessage` String

  The message created by the error by default.

#### Returns:

String: The final error message, containing either or both.

### `_getCount`

() protected static

Defined in `test/js/Assert.js:43`

Returns the number of assertions that have been performed.

### `_increment`

() protected static

Defined in `test/js/Assert.js:53`

Increments the number of assertions that have been performed.

### `_reset`

() protected static

Defined in `test/js/Assert.js:63`

Resets the number of assertions that have been performed to 0.

### `areEqual`

(

- `expected`
- `actual`
- `message`

)
static

Defined in `test/js/Assert.js:100`

Asserts that a value is equal to another. This uses the double equals sign so type coercion may occur.

#### Parameters:

- `expected` Object

  The expected value.

- `actual` Object

  The actual value to test.

- `message` String

  (Optional) The message to display if the assertion fails.

### `areNotEqual`

(

- `unexpected`
- `actual`
- `message`

)
static

Defined in `test/js/Assert.js:116`

Asserts that a value is not equal to another. This uses the double equals sign so type coercion may occur.

#### Parameters:

- `unexpected` Object

  The unexpected value.

- `actual` Object

  The actual value to test.

- `message` String

  (Optional) The message to display if the assertion fails.

### `areNotSame`

(

- `unexpected`
- `actual`
- `message`

)
static

Defined in `test/js/Assert.js:133`

Asserts that a value is not the same as another. This uses the triple equals sign so no type coercion may occur.

#### Parameters:

- `unexpected` Object

  The unexpected value.

- `actual` Object

  The actual value to test.

- `message` String

  (Optional) The message to display if the assertion fails.

### `areSame`

(

- `expected`
- `actual`
- `message`

)
static

Defined in `test/js/Assert.js:149`

Asserts that a value is the same as another. This uses the triple equals sign so no type coercion may occur.

#### Parameters:

- `expected` Object

  The expected value.

- `actual` Object

  The actual value to test.

- `message` String

  (Optional) The message to display if the assertion fails.

### `fail`

(

- `message`

)
static

Defined in `test/js/Assert.js:77`

Forces an assertion error to occur.

#### Parameters:

- `message` String

  (Optional) The message to display with the failure.

### `isArray`

(

- `actual`
- `message`

)
static

Defined in `test/js/Assert.js:296`

Asserts that a value is an array.

#### Parameters:

- `actual` Object

  The value to test.

- `message` String

  (Optional) The message to display if the assertion fails.

### `isBoolean`

(

- `actual`
- `message`

)
static

Defined in `test/js/Assert.js:316`

Asserts that a value is a Boolean.

#### Parameters:

- `actual` Object

  The value to test.

- `message` String

  (Optional) The message to display if the assertion fails.

### `isFalse`

(

- `actual`
- `message`

)
static

Defined in `test/js/Assert.js:169`

Asserts that a value is false. This uses the triple equals sign so no type coercion may occur.

#### Parameters:

- `actual` Object

  The actual value to test.

- `message` String

  (Optional) The message to display if the assertion fails.

### `isFunction`

(

- `actual`
- `message`

)
static

Defined in `test/js/Assert.js:330`

Asserts that a value is a function.

#### Parameters:

- `actual` Object

  The value to test.

- `message` String

  (Optional) The message to display if the assertion fails.

### `isInstanceOf`

(

- `expected`
- `actual`
- `message`

)
static

Defined in `test/js/Assert.js:344`

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.

#### Parameters:

- `expected` Function

  The function that the object should be an instance of.

- `actual` Object

  The object to test.

- `message` String

  (Optional) The message to display if the assertion fails.

### `isNaN`

(

- `actual`
- `message`

)
static

Defined in `test/js/Assert.js:204`

Asserts that a value is not a number.

#### Parameters:

- `actual` Object

  The value to test.

- `message` String

  (Optional) The message to display if the assertion fails.

### `isNotNaN`

(

- `actual`
- `message`

)
static

Defined in `test/js/Assert.js:218`

Asserts that a value is not the special NaN value.

#### Parameters:

- `actual` Object

  The value to test.

- `message` String

  (Optional) The message to display if the assertion fails.

### `isNotNull`

(

- `actual`
- `message`

)
static

Defined in `test/js/Assert.js:232`

Asserts that a value is not null. This uses the triple equals sign so no type coercion may occur.

#### Parameters:

- `actual` Object

  The actual value to test.

- `message` String

  (Optional) The message to display if the assertion fails.

### `isNotUndefined`

(

- `actual`
- `message`

)
static

Defined in `test/js/Assert.js:247`

Asserts that a value is not undefined. This uses the triple equals sign so no type coercion may occur.

#### Parameters:

- `actual` Object

  The actual value to test.

- `message` String

  (Optional) The message to display if the assertion fails.

### `isNull`

(

- `actual`
- `message`

)
static

Defined in `test/js/Assert.js:262`

Asserts that a value is null. This uses the triple equals sign so no type coercion may occur.

#### Parameters:

- `actual` Object

  The actual value to test.

- `message` String

  (Optional) The message to display if the assertion fails.

### `isNumber`

(

- `actual`
- `message`

)
static

Defined in `test/js/Assert.js:361`

Asserts that a value is a number.

#### Parameters:

- `actual` Object

  The value to test.

- `message` String

  (Optional) The message to display if the assertion fails.

### `isObject`

(

- `actual`
- `message`

)
static

Defined in `test/js/Assert.js:375`

Asserts that a value is an object.

#### Parameters:

- `actual` Object

  The value to test.

- `message` String

  (Optional) The message to display if the assertion fails.

### `isString`

(

- `actual`
- `message`

)
static

Defined in `test/js/Assert.js:389`

Asserts that a value is a string.

#### Parameters:

- `actual` Object

  The value to test.

- `message` String

  (Optional) The message to display if the assertion fails.

### `isTrue`

(

- `actual`
- `message`

)
static

Defined in `test/js/Assert.js:184`

Asserts that a value is true. This uses the triple equals sign so no type coercion may occur.

#### Parameters:

- `actual` Object

  The actual value to test.

- `message` String

  (Optional) The message to display if the assertion fails.

### `isTypeOf`

(

- `expectedType`
- `actualValue`
- `message`

)
static

Defined in `test/js/Assert.js:403`

Asserts that a value is of a particular type.

#### Parameters:

- `expectedType` String

  The expected type of the variable.

- `actualValue` Object

  The actual value to test.

- `message` String

  (Optional) The message to display if the assertion fails.

### `isUndefined`

(

- `actual`
- `message`

)
static

Defined in `test/js/Assert.js:277`

Asserts that a value is undefined. This uses the triple equals sign so no type coercion may occur.

#### Parameters:

- `actual` Object

  The actual value to test.

- `message` String

  (Optional) The message to display if the assertion fails.

### `pass`

() static

Defined in `test/js/Assert.js:87`

A marker that the test should pass.

### `throwsError`

(

- `expectedError`
- `method`
- `message`

)
Void static

Defined in `test/js/Assert.js:422`

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 | Object

  If 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` Function

  The method to execute that should throw the error.

- `message` String

  (Optional) The message to display if the assertion fails.

#### Returns:

Void:

## Properties

### `_asserts`

Int private

Defined in `test/js/Assert.js:13`

The number of assertions performed.