Assertions run test functions, provide helpers, and record the results of the tests.
this.assert_equal("Tiger", this.name, "Tiger was expected");
this.assert_not_null(this.title, "Title was null");
this.assert_null(this.obj, "Expected to be null");
this.assert(x_value > 200);
new MVC.Test.Assertions(test, test_name) -> Assertion
Creates a new Assertion with the given test for the test that matches test_name.
assert(expression,message) -> undefined
Asserts the expression exists in the same way that if(expression) does. If the expression doesn't exist reports the error.
new MVC.Test.Unit('TestCase Name',{
test_some_asserts : function(){
this.assert(true) //passes
this.assert({}) //passes
this.assert([]) //passes
this.assert(7) //passes
this.assert(0) //fails
this.assert(false) //fails
this.assert('') //fails
this.assert(null) //fails
this.assert(undefined,
"Something was expected.") //fails
}
)
assert_each(expected, actual, expression) -> undefined
Asserts each element in the actual array matches each element in the expected array. If one element doesn't match, it fails.
this.assert_each([1,2,3], my_array, "Array not valid");
assert_equal(expected, actual, message) -> undefined
Uses the double equals (==) to determine if two values are equal. This means that type coercion may occur. For example 5 == '5'.
new MVC.Test.Unit('TestCase Name',{
test_some_asserts : function(){
this.assert_equal(7,7) //passes
this.assert_equal(7,'7') //passes
this.assert_equal('s','s') //passes
this.assert_equal(0,false) //passes
this.assert_equal("Tiger", this.name, "Tiger was expected");
this.assert_equal(6,7) //fails
}
)
assert_null(object, expression) -> undefined
Passes if the given object == null. Fails otherwise.
this.assert_null(this.obj, "Expected to be null");
assert_not(expression, message) -> undefined
Passes if the expression is false, fails if it is true
this.assert_not(x_value == 200);
assert_not_null(object, message) -> undefined
Passes if object is != null, fails otherwise
this.assert_not_null(obj);
pass() -> undefined
Adds to the assertions pass count.
fail(message) -> undefined
Adds to the assertions failure count with a message.
error(message) -> undefined
Adds to the error count and adds the message to the assertions messages array.
next(params, delay, fname) -> undefined
Calls the next function in the array after a certain delay. Used at the end of a test function after an asynchronous event has been initiated, such as an Ajax call or an animation.
test_open_directory: function(){
// call the next function after a delay of 2 seconds
this.next(this.DirectoryDblclick(2), 2, 'verify_open');
},
verify_open: function(){
this.assert_equal(5, params.element.childNodes.length);
}
next_callback(fname, delay) -> undefined
Calls the next function in the array after a certain delay. Used in conjunction with asynchronous functions that use callback functions, such as an Ajax call or the Drag event.
test_drag: function(){
this.Drag($E('draggable'),{from: 'pointA', to: 'pointB',
duration: 2, callback: this.next_callback('done_dragging', 3)})
},
done_dragging : function(){
this.assert_equal(1, $E('pointB').next().childNodes.length);
}