Fetching templates in tests using jqUnit

Michelle D'Souza michelle.dsouza at utoronto.ca
Thu Jul 16 15:45:28 UTC 2009


Hi developers,

I've made a couple improvements to jqUnit and thought you'd be  
interested.

I've added a function to TestCase in jqUnit that fetches a template  
and inserts it into the page. One common use of this would be to set  
up the DOM with the component's html template prior to running the  
tests. Note that QUnit reverts the DOM back to original page load  
after each test so the template would need to be inserted at the  
beginning of each test - ideally using the 'setup' function that is a  
parameter to TestCase creation. The 'fetchTemplate' function caches  
the fetched template so that an AJAX call is only done the first time.

If you look at the code for 'fetchTemplate' you'll notice the use of  
'stop' and 'start'. These are QUnit functions that pause the test  
runner while waiting for the AJAX response. The way to use them is to  
call 'stop' prior to your ajax call and call 'start' in the ajax  
callback.

I also took the opportunity to 'thatify' TestCase so there are now two  
ways to create a TestCase - using the creator function  
'jqUnit.testCase' or using the constructor 'jqUnit.TestCase'.

Michelle

------------------------------------------------------
Michelle D'Souza
Software Developer, Fluid Project
Adaptive Technology Resource Centre
University of Toronto






More information about the fluid-work mailing list