asserts.js
No description.

File Location

/goog/testing/asserts.js

Classes


Public Protected Private

Global Functions

PRIMITIVE_EQUALITY_PREDICATES.Boolean()
No description.
code »
DOUBLE_EQUALITY_PREDICATE()
No description.
code »
PRIMITIVE_EQUALITY_PREDICATES.Date()
No description.
code »
PRIMITIVE_EQUALITY_PREDICATES.Function()
No description.
code »
PRIMITIVE_EQUALITY_PREDICATES.Number()
No description.
code »
goog.testing.asserts.primitiveRoughEqualityPredicates_.Number()
No description.
code »
PRIMITIVE_EQUALITY_PREDICATES.RegExp()
No description.
code »
PRIMITIVE_EQUALITY_PREDICATES.String()
No description.
code »
TO_STRING_EQUALITY_PREDICATE()
No description.
code »
_assert()
No description.
code »
_displayStringForValue()
No description.
code »
_trueTypeOf()
No description.
code »
_validateArguments()
No description.
code »
argumentsIncludeComments()
No description.
code »
assert(aopt_b)
No description.
Arguments:
a : *
The value to assert (1 arg) or debug message (2 args).
opt_b : *=
The value to assert (2 args only).
code »
assertArrayEquals(abopt_c)
Compares two arrays ignoring negative indexes and extra properties on the array objects. Use case: Internet Explorer adds the index, lastIndex and input enumerable fields to the result of string.match(/regexp/g), which makes assertObjectEquals fail.
Arguments:
a : *
The expected array (2 args) or the debug message (3 args).
b : *
The actual array (2 args) or the expected array (3 args).
opt_c : *=
The actual array (3 args only).
code »
assertCSSValueEquals(abcopt_d)
Compares two CSS property values to make sure that they represent the same things. This will normalize values in the browser. For example, in Firefox, this assertion will consider "rgb(0, 0, 255)" and "#0000ff" to be identical values for the "color" property. This function won't normalize everything -- for example, in most browsers, "blue" will not match "#0000ff". It is intended only to compensate for unexpected normalizations performed by the browser that should also affect your expected value.
Arguments:
a : string
Assertion message, or the CSS property name.
b : string
CSS property name, or the expected value.
c : string
The expected value, or the actual value.
opt_d : string=
The actual value.
code »
assertContains(abopt_c)
Checks if the given element is the member of the given container.
Arguments:
a : *
Failure message (3 arguments) or the contained element (2 arguments).
b : *
The contained element (3 arguments) or the container (2 arguments).
opt_c : *=
The container.
code »
assertElementsEquals(abopt_c)
Compares two objects that can be accessed like an array and assert that each element is equal.
Arguments:
a : string | Object
Failure message (3 arguments) or object #1 (2 arguments).
b : Object
Object #1 (2 arguments) or object #2 (3 arguments).
opt_c : Object=
Object #2 (3 arguments).
code »
assertElementsRoughlyEqual(abcopt_d)
Compares two objects that can be accessed like an array and assert that each element is roughly equal.
Arguments:
a : string | Object
Failure message (4 arguments) or object #1 (3 arguments).
b : Object
Object #1 (4 arguments) or object #2 (3 arguments).
c : Object | number
Object #2 (4 arguments) or tolerance (3 arguments).
opt_d : number=
tolerance (4 arguments).
code »
assertEquals(abopt_c)
No description.
Arguments:
a : *
The expected value (2 args) or the debug message (3 args).
b : *
The actual value (2 args) or the expected value (3 args).
opt_c : *=
The actual value (3 args only).
code »
assertEvaluatesToFalse(aopt_b)
No description.
Arguments:
a : *
The value to assert (1 arg) or debug message (2 args).
opt_b : *=
The value to assert (2 args only).
code »
assertEvaluatesToTrue(aopt_b)
No description.
Arguments:
a : *
The value to assert (1 arg) or debug message (2 args).
opt_b : *=
The value to assert (2 args only).
code »
assertFalse(aopt_b)
No description.
Arguments:
a : *
The value to assert (1 arg) or debug message (2 args).
opt_b : *=
The value to assert (2 args only).
code »
assertHTMLEquals(abopt_c)
Compares two HTML snippets. Take extra care if attributes are involved. assertHTMLEquals's implementation isn't prepared for complex cases. For example, the following comparisons erroneously fail:
assertHTMLEquals('', '');
assertHTMLEquals('
', '
'); assertHTMLEquals('
When in doubt, use goog.testing.dom.assertHtmlMatches.
Arguments:
a : *
The expected value (2 args) or the debug message (3 args).
b : *
The actual value (2 args) or the expected value (3 args).
opt_c : *=
The actual value (3 args only).
code »
assertHashEquals(abopt_c)
No description.
Arguments:
a : *
The expected value (2 args) or the debug message (3 args).
b : *
The actual value (2 args) or the expected value (3 args).
opt_c : *=
The actual value (3 args only).
code »
assertNaN(aopt_b)
No description.
Arguments:
a : *
The value to assert (1 arg) or debug message (2 args).
opt_b : *=
The value to assert (2 args only).
code »
assertNonEmptyString(aopt_b)
No description.
Arguments:
a : *
The value to assert (1 arg) or debug message (2 args).
opt_b : *=
The value to assert (2 args only).
code »
assertNotContains(abopt_c)
Checks if the given element is not the member of the given container.
Arguments:
a : *
Failure message (3 arguments) or the contained element (2 arguments).
b : *
The contained element (3 arguments) or the container (2 arguments).
opt_c : *=
The container.
code »
assertNotEquals(abopt_c)
No description.
Arguments:
a : *
The expected value (2 args) or the debug message (3 args).
b : *
The actual value (2 args) or the expected value (3 args).
opt_c : *=
The actual value (3 args only).
code »
assertNotNaN(aopt_b)
No description.
Arguments:
a : *
The value to assert (1 arg) or debug message (2 args).
opt_b : *=
The value to assert (2 args only).
code »
assertNotNull(aopt_b)
No description.
Arguments:
a : *
The value to assert (1 arg) or debug message (2 args).
opt_b : *=
The value to assert (2 args only).
code »
assertNotNullNorUndefined(aopt_b)
No description.
Arguments:
a : *
The value to assert (1 arg) or debug message (2 args).
opt_b : *=
The value to assert (2 args only).
code »
assertNotThrows(aopt_b) *
Asserts that the function does not throw an error.
Arguments:
a : !(string | Function)
The assertion comment or the function to call.
opt_b : !Function=
The function to call (if the first argument of assertNotThrows was the comment).
Returns: *  The return value of the function.
code »
assertNotUndefined(aopt_b)
No description.
Arguments:
a : *
The value to assert (1 arg) or debug message (2 args).
opt_b : *=
The value to assert (2 args only).
code »
assertNull(aopt_b)
No description.
Arguments:
a : *
The value to assert (1 arg) or debug message (2 args).
opt_b : *=
The value to assert (2 args only).
code »
assertObjectEquals(abopt_c)
Notes: Object equality has some nasty browser quirks, and this implementation is not 100% correct. For example, var a = [0, 1, 2]; var b = [0, 1, 2]; delete a[1]; b[1] = undefined; assertObjectEquals(a, b); // should fail, but currently passes See asserts_test.html for more interesting edge cases. The first comparison object provided is the expected value, the second is the actual.
Arguments:
a : *
Assertion message or comparison object.
b : *
Comparison object.
opt_c : *=
Comparison object, if an assertion message was provided.
code »
assertObjectNotEquals(abopt_c)
Compares two arbitrary objects for non-equalness. All the same caveats as for assertObjectEquals apply here: Undefined values may be confused for missing values, or vice versa.
Arguments:
a : *
Assertion message or comparison object.
b : *
Comparison object.
opt_c : *=
Comparison object, if an assertion message was provided.
code »
assertObjectRoughlyEquals(abcopt_d)
Similar to assertObjectEquals above, but accepts a tolerance margin.
Arguments:
a : *
Assertion message or comparison object.
b : *
Comparison object.
c : *
Comparison object or tolerance.
opt_d : *=
Tolerance, if an assertion message was provided.
code »
assertRegExp(abopt_c)
Checks if the given string matches the given regular expression.
Arguments:
a : *
Failure message (3 arguments) or the expected regular expression as a string or RegExp (2 arguments).
b : *
The regular expression (3 arguments) or the string to test (2 arguments).
opt_c : *=
The string to test.
code »
assertRoughlyEquals(abcopt_d)
No description.
Arguments:
a : *
The expected value (3 args) or the debug message (4 args).
b : *
The actual value (3 args) or the expected value (4 args).
c : *
The tolerance (3 args) or the actual value (4 args).
opt_d : *=
The tolerance (4 args only).
code »
assertSameElements(abopt_c)
Compares two array-like objects without taking their order into account.
Arguments:
a : string | goog.testing.asserts.ArrayLike
Assertion message or the expected elements.
b : goog.testing.asserts.ArrayLike
Expected elements or the actual elements.
opt_c : goog.testing.asserts.ArrayLike=
Actual elements.
code »
assertThrows(aopt_b) *
Asserts that the function throws an error.
Arguments:
a : !(string | Function)
The assertion comment or the function to call.
opt_b : !Function=
The function to call (if the first argument of assertThrows was the comment).
Returns: *  The error thrown by the function.
code »
assertThrowsJsUnitException(callbackopt_expectedMessage)
Asserts that the given callback function results in a JsUnitException when called, and that the resulting failure message matches the given expected message.
Arguments:
callback : function() : void
Function to be run expected to result in a JsUnitException (usually contains a call to an assert).
opt_expectedMessage : string=
Failure message expected to be given with the exception.
code »
assertTrue(aopt_b)
No description.
Arguments:
a : *
The value to assert (1 arg) or debug message (2 args).
opt_b : *=
The value to assert (2 args only).
code »
assertUndefined(aopt_b)
No description.
Arguments:
a : *
The value to assert (1 arg) or debug message (2 args).
opt_b : *=
The value to assert (2 args only).
code »
goog.testing.asserts.callWithoutLogging(fn)
Runs a function in an environment where test failures are not logged. This is useful for testing test code, where failures can be a normal part of a test.
Arguments:
fn : function() : void
Function to run without logging failures.
code »
commentArg()
No description.
code »
goog.testing.asserts.contains_(containercontained) boolean
Tells whether the array contains the given element.
Arguments:
container : goog.testing.asserts.ArrayLike
The array to find the element in.
contained : *
Element to find.
Returns: boolean  Whether the element is in the array.
code »
assertObjectRoughlyEquals&equalityPredicate()
No description.
code »
fail()
No description.
code »
goog.testing.asserts.findDifferences(expectedactualopt_equalityPredicate) ?string
Determines if two items of any type match, and formulates an error message if not.
Arguments:
expected : *
Expected argument to match.
actual : *
Argument as a result of performing the test.
opt_equalityPredicate : (function(string, *, *): ?string)=
An optional function that can be used to check equality of variables. It accepts 3 arguments: type-of-variables, var1, var2 (in that order) and returns an error message if the variables are not equal, goog.testing.asserts.EQUALITY_PREDICATE_VARS_ARE_EQUAL if the variables are equal, or goog.testing.asserts.EQUALITY_PREDICATE_CANT_PROCESS if the predicate couldn't check the input variables. The function will be called only if the types of var1 and var2 are identical.
Returns: ?string  Null on success, error message on failure.
code »
goog.testing.asserts.getDefaultErrorMsg_(expectedactual) string
No description.
Arguments:
expected : *
The expected value.
actual : *
The actual value.
Returns: string  A failure message of the values don't match.
code »
goog.testing.asserts.indexOf_(containercontained) number
Finds the position of the first occurrence of an element in a container.
Arguments:
container : goog.testing.asserts.ArrayLike
The array to find the element in.
contained : *
Element to find.
Returns: number  Index of the first occurrence or -1 if not found.
code »
goog.testing.asserts.findDifferences&innerAssert()
No description.
code »
goog.testing.asserts.findDifferences&innerAssert_(var1var2path)
No description.
Arguments:
var1 : *
An item in the expected object.
var2 : *
The corresponding item in the actual object.
path : string
Their path in the objects.
code »
goog.testing.asserts.isArrayIndexProp_(prop) boolean
Helper function for assertObjectEquals.
Arguments:
prop : string
A property name.
Returns: boolean  If the property name is an array index.
code »
nonCommentArg()
No description.
code »
goog.testing.asserts.numberRoughEqualityPredicate_(var1var2tolerance) boolean
Compares equality of two numbers, allowing them to differ up to a given tolerance.
Arguments:
var1 : number
A number.
var2 : number
A number.
tolerance : number
the maximum allowed difference.
Returns: boolean  Whether the two variables are sufficiently close.
code »
goog.testing.asserts.getDefaultErrorMsg_&printString()
No description.
code »
goog.testing.asserts.raiseException(commentopt_message)
Raises a JsUnit exception with the given comment.
Arguments:
comment : string
A summary for the exception.
opt_message : string=
A description of the exception.
code »
standardizeCSSValue(propertyNamevalue) string
Standardizes a CSS value for a given property by applying it to an element and then reading it back.
Arguments:
propertyName : string
CSS property name.
value : string
CSS value.
Returns: string  Normalized CSS value.
code »
standardizeHTML()
No description.
code »
goog.testing.asserts.toArray_(arrayLike) !Array
Converts an array like object to array or clones it if it's already array.
Arguments:
arrayLike : goog.testing.asserts.ArrayLike
The collection.
Returns: !Array  Copy of the collection as array.
code »
assertObjectRoughlyEquals&equalityPredicate&typedPredicate()
No description.
code »

Global Variables

JSUNIT_UNDEFINED_VALUE :
No description.
Code »
PRIMITIVE_EQUALITY_PREDICATES :
No description.
Code »

Directory testing

File Reference