goog.testing.asserts
Functions
assert( a, opt_b ) → void
void
Parameters |
|
---|
assertArrayEquals( a, b, opt_c ) → void
void
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.
Parameters |
|
---|
assertCSSValueEquals( a, b, c, opt_d ) → void
void
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.
Parameters |
|
---|
assertContains( a, b, opt_c ) → void
void
Checks if the test value is included in the given container. The container
can be a string (where "included" means a substring), an array or any
IArrayLike
(where "included" means a member), or any type implementing
indexOf
with similar semantics (returning -1 for not included).
Parameters |
|
---|
assertElementsEquals( a, b, opt_c ) → void
void
assertElementsRoughlyEqual( a, b, c, opt_d ) → void
void
Compares two objects that can be accessed like an array and assert that each element is roughly equal.
Parameters |
|
---|
assertEquals( a, b, opt_c ) → void
void
Parameters |
|
---|
assertEvaluatesToFalse( a, opt_b ) → void
void
Parameters |
|
---|
assertEvaluatesToTrue( a, opt_b ) → void
void
Parameters |
|
---|
assertFalse( a, opt_b ) → void
void
Parameters |
|
---|
assertHTMLEquals( a, b, opt_c ) → void
void
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
.
Parameters |
|
---|
assertHashEquals( a, b, opt_c ) → void
void
Parameters |
|
---|
assertNaN( a, opt_b ) → void
void
Parameters |
|
---|
assertNonEmptyString( a, opt_b ) → void
void
Parameters |
|
---|
assertNotContains( a, b, opt_c ) → void
void
Checks if the test value is not included in the given container. The
container can be a string (where "included" means a substring), an array or
any IArrayLike
(where "included" means a member), or any type implementing
indexOf
with similar semantics (returning -1 for not included).
Parameters |
|
---|
assertNotEquals( a, b, opt_c ) → void
void
Parameters |
|
---|
assertNotNaN( a, opt_b ) → void
void
Parameters |
|
---|
assertNotNull( a, opt_b ) → void
void
Parameters |
|
---|
assertNotNullNorUndefined( a, opt_b ) → void
void
Parameters |
|
---|
assertNotThrows( a, opt_b ) → *
*
Asserts that the function does not throw an error.
Parameters |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
Returns |
| ||||||||
Throws |
|
assertNotUndefined( a, opt_b ) → void
void
Parameters |
|
---|
assertNull( a, opt_b ) → void
void
Parameters |
|
---|
assertNullOrUndefined( a, opt_b ) → void
void
Parameters |
|
---|
assertObjectEquals( a, b, opt_c ) → void
void
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.
Parameters |
|
---|
assertObjectNotEquals( a, b, opt_c ) → void
void
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.
Parameters |
|
---|
assertObjectRoughlyEquals( a, b, c, opt_d ) → void
void
Similar to assertObjectEquals above, but accepts a tolerance margin.
Parameters |
|
---|
assertRegExp( a, b, opt_c ) → void
void
Checks if the given string matches the given regular expression.
Parameters |
|
---|
assertRejects( a, opt_b ) → IThenable<*>
IThenable<*>
Asserts that the IThenable rejects.
This is useful for asserting that async functions throw, like an asynchronous assertThrows. Example:
async function shouldThrow() { throw new Error('error!'); }
async function testShouldThrow() {
const error = await assertRejects(shouldThrow());
assertEquals('error!', error.message);
}
Parameters |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
Returns |
|
assertRoughlyEquals( a, b, c, opt_d ) → void
void
Parameters |
|
---|
assertSameElements( a, b, opt_c ) → void
void
Compares elements of two array-like or iterable objects using strict equality without taking their order into account.
Parameters |
|
---|
assertThrows( a, opt_b ) → Error
Error
Asserts that the function throws an error.
Parameters |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
Returns |
| ||||||||
Throws |
|
assertThrowsJsUnitException( callback, opt_expectedMessage ) → goog.testing.JsUnitException
goog.testing.JsUnitException
Asserts that the given callback function results in a JsUnitException when called, and that the resulting failure message matches the given expected message.
Parameters |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
Returns |
| ||||||||
Throws |
|
assertTrue( a, opt_b ) → void
void
Parameters |
|
---|
assertUndefined( a, opt_b ) → void
void
Parameters |
|
---|
clearCustomComparator( prototype ) → boolean
boolean
fail( failureMessage ) → void
void
Parameters |
|
---|
findDifferences( expected, actual, opt_equalityPredicate ) → (string|null)
(string|null)
Determines if two items of any type match, and formulates an error message if not.
Parameters |
| ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Returns |
|
raiseException( comment, opt_message ) → void
void
registerComparator( prototype, fn ) → void
void
Marks the given prototype as having equality semantics provided by the given custom equality function.
This will cause findDifferences and assertObjectEquals to use the given function when comparing objects with this prototype. When comparing two objects with different prototypes, the equality (if any) attached to their lowest common ancestor in the prototype hierarchy will be used.
Parameters |
|
---|
Properties
No information.
ComparisonResult → (string|undefined)
(string|undefined)
The result of a comparison performed by an EqualityFunction: if undefined, the inputs are equal; otherwise, a human-readable description of their inequality.
A equality predicate.
The first two arguments are the values to be compared. The third is an equality function which can be used to recursively apply findDifferences.
An example comparison implementation for Array could be:
function arrayEq(a, b, eq) { if (a.length !== b.length) { return "lengths unequal"; }
const differences = []; for (let i = 0; i < a.length; i++) { // Use the findDifferences implementation to perform recursive // comparisons. const diff = eq(a[i], b[i], eq); if (diff) { differences[i] = diff; } }
if (differences) {
return found array differences: ${differences}
;
}
// Otherwise return undefined, indicating no differences. return undefined; }