Documentation

include MVC MVC.Animate MVC.Class MVC.Controller MVC.Controller.Action MVC.Controller.Action.Drag MVC.Controller.Action.Drop MVC.Controller.Action.EnterLeave MVC.Controller.Action.Event MVC.Controller.Action.Hover MVC.Controller.Action.Lasso MVC.Controller.Action.Selectable MVC.Controller.Action.Subscribe MVC.Controller.Comet MVC.Controller.Params MVC.Controller.Params.Drag MVC.Controller.Params.Drop MVC.Controller.Stateful MVC.Delegator MVC.Doc MVC.Element MVC.Event MVC.File MVC.History MVC.IO MVC.IO.Ajax MVC.IO.Comet MVC.IO.JsonP MVC.IO.WindowName MVC.IO.XDoc MVC.Model MVC.Model.Ajax MVC.Model.Cookie MVC.Model.JsonP MVC.Model.JsonRest MVC.Model.WindowName MVC.Model.XmlRest MVC.Native MVC.Native.Array MVC.Native.Date MVC.Native.Function MVC.Native.Number MVC.Native.Object MVC.Native.String MVC.Options MVC.Store MVC.SyntheticEvent MVC.Test MVC.Test.Assertions MVC.Test.Controller MVC.Test.Functional MVC.Test.Runner MVC.Test.Unit MVC.Timer MVC.Timer.Easings MVC.Vector MVC.View MVC.View.Helpers OpenAjax

MVC.Test.Assertions

Inherits: MVC.Class
Assertions run test functions, provide helpers, and record the results of the tests.

Example

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);

Prototype Methods

assert

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
  }
)
{Object} - expression to be evaluated
{String} - An optional message. A default is provided if the message isn't present.

assert_each

assert_each(expected, actual, message) -> undefined
Asserts each value in the actual array equals the same value in the expected array
{Object} -
{Object} -
{String} - An optional message. A default is provided if the message isn't present.

assert_equal

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
  }
)
{Object} - the expected value
{Object} - The variable to check for or the value being checked
{String} - An optional message. A default is provided if the message isn't present.

assert_not

assert_not(expression, message) -> undefined
Passes if the expression is false, fails if it is true
 this.assert_not(x_value == 200);
{Object} - An expression
{String} - An optional message. A default is provided if the message isn't present.

assert_not_null

assert_not_null(object, message) -> undefined
Passes if object is != null, fails otherwise
 this.assert_not_null(obj);
{Object} - The object to check for null param {optional:String} message An optional message. A default is provided if the message isn't present.
{} -

assert_null

assert_null(obj, message) -> undefined
Passes if the given object == null. Fails otherwise.
 this.assert_null(this.obj, "Expected to be null");
{Object} - The object to check for null
{String} - An optional message. A default is provided if the message isn't present.

error

error(error) -> undefined
Adds to the error count and adds the message to the assertions messages array.
{Object} - Error message object that includes a name and message.

fail

fail(message) -> undefined
Adds to the assertions failure count with a message.
{String} - error message

init

init(test, test_name) -> undefined
Creates a new Assertion with the given test for the test that matches test_name.
{MVC.Test} - An instance of a MVC.Test class.
{Function} - A function name.

next

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.
{Object} - Optional parameters. If provided, this is passed into the function specified by fname as its parameter.
{Number} - An optional delay, after which the specified function is called. The default is 0.5 seconds.
{String} - An optional function name. If none is give, defaults to the name of the function sequentially next in the array of test functions.

next_callback

next_callback(fname, delay) -> Function
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);
}
{Object} - An optional function name. If none is give, defaults to the name of the function sequentially next in the array of test functions.
{Object} - An optional delay, after which the specified function is called. The default is 0.5 seconds.
{Function} - the function used for callbacks

pass

pass() -> undefined
Adds to the assertions pass count.