JSUnit Widget ============= Installation ------------ :: easy_install tw.jsunit Usage ----- The JSUnit Widget can be used to create testpages for testing javascript code using the `JSUnit javascript unit testing framework `_. The package also includes a Runner Widget that sets up the environment for running the JSUnit testRunner off a TurboGears webapp as seen in the online testRunner example `here `_. The tutorial is divided into two parts. The first part demonstrates the usage in testing custom javascript code used in a TurboGears Application and the second part demonstrates the usage in testing javascript code in a ToscaWidget. Testing Javascript Code in TurboGears App ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ When testing javascript code in a TG app, the JSUnit widget can be used by creating two additional controller methods. One for running the testRunner and the other for loading the testsuite. The method for running the testRunner must instantiate and place the Runner widget in the template context. Similarly the method for loading the testsuite must instantiate the JSUnit widget. The following code block shows the usage:: from tw.jsunit import JSUnit, Runner class RootController(BaseController): @expose('samplejsunit.templates.runner') def runner(self, **kw): pylons.c.runner = Runner(testpage='/runpage') return dict() @expose('samplejsunit.templates.runpage') def runpage(self, **kw): pylons.c.jsunit = JSUnit() return dict() We also need to create two templates. One for the testRunner and one for the testsuite. The template for the testRunner should include the runner widget:: ${tmpl_context.runner(value=value)} The template for the testsuite should include the JSUnit widget and the javascript file containing the test functions. It should also include javascript files where the functions to be tested are defined::