         $container.addClass config.className if config.className?
         $test = $test.addClass 'visual-test-fragment'
                      .filter '.visual-test-fragment'
-      # - Run tests.
+
       config.beforeTest $test if config.beforeTest?
       config.test $test
 
-  # Helpers for additional setup.
   _.extend $.visualTest,
-    # A button for appending an item to a list.
-    # This should be included as part of `footerHtml`.
     setupAppendButton: ($context, listSelector, updateItem) ->
       $list = $context.find listSelector
       $item = $list.children(':last-child').clone()

        $list.append $newItem
        updateItem $newItem if updateItem?

  # Simple method for an element to render and append a test. Only provide a
  # custom template if absolutely needed.
  $.fn.renderVisualTest = (vars, opts) ->
    opts ?= {}
    _.defaults opts, $.fn.renderVisualTest.defaults

  'underscore'
], ($, _) ->

  # __$.visualTest__ returns a configured test function generator. Tests should
  # be invoked tests on document ready. Configuration:
  # 
  # - `label` - header text describing the test topic.
  # - `anchorName` - for the section on its docs page, used to generate `docsUrl`.
  # - `asFragments` - will render the test differently, directly inside `<body>`.
  # - `className` - a hook for any custom css.
  # - `footerHtml` - optional html for controls for additional testing.
  #
  # It will:
  # 1. Ensure config.
  # 2. Build test template vars.
  # 3. Render test to get test context (or fragments).
  # 4. Run tests.
  #
  # It also includes helpers for additional setup. `setupAppendButton` inits a
  # button for appending an item to a list, and should be included as part of
  # `footerHtml`.
  $.visualTest = (config) ->
    ->
      config.vars ?= {}

      vars = _.pick config, 'label', 'className', 'footerHtml'
      vars.footerHtml ?= '' unless config.asFragments
      vars.docsUrl = $('body > header [data-rel=docs]').attr('href') + "##{config.anchorName}"
      vars.html = _.template config.template, config.vars

      $container = if config.asFragments then $('body') else $('#main')
      opts = { template: '<%= html %>' } if config.asFragments
      $test = $container.renderVisualTest vars, opts
