My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Assertions  
Documentation for the default assertions in JsTestDriver.
Updated Aug 5, 2010 by corbinrs...@gmail.com

Default Assertions

fail([msg])

Throws a JavaScript Error with given message string.

assert([msg], actual)

assertTrue([msg], actual)

Fails if the result isn't truthy. To use a message, add it as the first parameter.

assertFalse([msg], actual)

Fails if the result isn't falsy.

assertEquals([msg], expected, actual)

Fails if the expected and actual values can not be compared to be equal.

assertNotEquals([msg], expected, actual)

Fails if the expected and actual values can be compared to be equal.

assertSame([msg], expected, actual)

Fails if the expected and actual values are not references to the same object.

assertNotSame([msg], expected, actual)

Fails if the expected and actual are references to the same object.

assertNull([msg], actual)

Fails if the given value is not exactly null.

assertNotNull([msg], actual)

Fails if the given value is exactly null.

assertUndefined([msg], actual)

Fails if the given value is not undefined.

assertNotUndefined([msg], actual)

Fails if the given value is undefined.

assertNaN([msg], actual)

Fails if the given value is not a NaN.

assertNotNaN([msg], actual)

Fails if the given value is a NaN.

assertException([msg], callback, error)

Fails if the code in the callback does not throw the given error.

assertNoException([msg], callback)

Fails if the code in the callback throws an error.

assertArray([msg], actual)

Fails if the given value is not an Array.

assertTypeOf([msg], expected, value)

Fails if the JavaScript type of the value isn't the expected string.

assertBoolean([msg], actual)

Fails if the given value is not a Boolean. Convenience function to assertTypeOf.

assertFunction([msg], actual)

Fails if the given value is not a Function. Convenience function to assertTypeOf.

assertObject([msg], actual)

Fails if the given value is not an Object. Convenience function to assertTypeOf.

assertNumber([msg], actual)

Fails if the given value is not a Number. Convenience function to assertTypeOf.

assertString([msg], actual)

Fails if the given value is not a String. Convenience function to assertTypeOf.

assertMatch([msg], regexp, actual)

Fails if the given value does not match the given regular expression.

assertNoMatch([msg], regexp, actual)

Fails if the given value matches the given regular expression.

assertTagName([msg], tagName, element)

Fails if the given DOM element is not of given tagName.

assertClassName([msg], className, element)

Fails if the given DOM element does not have given CSS class name.

assertElementId([msg], id, element)

Fails if the given DOM element does not have given ID.

assertInstanceOf([msg], constructor, actual)

Fails if the given object is not an instance of given constructor.

assertNotInstanceOf([msg], constructor, actual)

Fails if the given object is an instance of given constructor.

Comment by mbaker....@gmail.com, Dec 6, 2010

Is there a way to add your own assert functions? We're doing it inline but ideally they would be defined in some central file.

Comment by bowdowntonoone, Jan 3, 2011
Comment by jer...@syapse.com, Jan 9, 2012

assertTrue's description should be updated: it no longer looks for "truthy" values; instead it now requires a boolean true, and gives an error "(AssertError?: Not a boolean: 1)" if you try to get by with a "truthy" value.

Personally, I think the assert would be more useful if it allowed "truthy" non-true values, but that's just my opinion. Either way though, I think the documentation should reflect what the assertion does.


Sign in to add a comment
Powered by Google Project Hosting