Test.Controller

MVC.Test.Controller, helpers

Related

Test.Assertions, Test.Unit, Test, Test.Functional

Functional tests are used to mimic user events.

Constructor

MVC.Test.Controller

new MVC.Test.Controller(controller_name, tests) -> Test

Creates a new functional test case. A test case is a collection of test functions and helpers.

new MVC.Controller('todos',{
  test_clicking_a_todo : function(){
    this.TodoClick(2)
  }
})
- The className of the correspoinding controller you are testing.
- An object with test functions. Functions that begin with test_ will be run as tests. Functions that don't begin with test are converted to helper functions. Do not name helper functions the same name as the test provided helpers and assertions such as assert or assertEqual as your functions will override these functions.

Inherited Methods

Test

fail, helpers, run, run_helper, run_test, toElement

Inherited Assertion Helpers

Functional

Action, Blur, Change, Click, Contextmenu, Dblclick, Drag, Keyup, Keydown, Mousedown, Mousemove, Mouseout, Mouseup, Select, Submit, Write

Prototype Methods

helpers

helpers()

Adds Controller specific helpers to Assertion Helpers.

Assertion Helpers

Test.Controller dynamically creates assertion helpers based on the tested controller's actions. For example, a Test.Controller that tests a controller like:

MVC.Controller('todos', {
  click : function( params ){ ... },	 //matches clicks on elements with className = 'todo'
  '# submit' : function(params) { ... }  //matches submits on elements with id = 'todos'
})

will have helpers like TodoClick and TodosSubmit:

new MVC.Test.Controller('todos', {
  test_click : function( ){ 
    this.TodoClick(2);  //clicks the 2nd element with className = 'todo'
  },	 
  '# submit' : function(params) {
    this.TodosSubmit();  //submits the first element with id = 'todos'
  }  
})

Pretty awesome! As we can't enumerate these helpers here, they are displayed in the testing window for each test. You can click on each one to see it in action on the first matching element.

Each generated helper takes only the options_or_number parameter:

GENERATED_HELPER(options_or_number)
- If a number is provided, it uses it to select that number from the array of elements returned by doing a CSSQuery with selector. If an object is provided, it passes those options to the SyntheticEvent for creation. If nothing is provided, the number defaults to 0.