<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog &#187; qunit</title>
	<atom:link href="http://monket.net/blog/tag/qunit/feed/" rel="self" type="application/rss+xml" />
	<link>http://monket.net/blog</link>
	<description></description>
	<lastBuildDate>Mon, 12 Apr 2010 13:11:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>QUnitAdapter 1.1.0</title>
		<link>http://monket.net/blog/2010/04/qunitadapter-1-1-0/</link>
		<comments>http://monket.net/blog/2010/04/qunitadapter-1-1-0/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 12:22:00 +0000</pubDate>
		<dc:creator>Karl O&#39;Keeffe</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js test driver]]></category>
		<category><![CDATA[qunit]]></category>

		<guid isPermaLink="false">http://monket.net/blog/?p=293</guid>
		<description><![CDATA[I&#8217;ve updated the JS Test Driver QUnitAdapter to improve compatibility with QUnit. Variables set on the this object within are now available within setup, teardown, and the tests themselves. module&#40;'Lifecycle', &#123; setup: function&#40;&#41; &#123; this.mockString = &#34;some string&#34;; &#125;, teardown: function&#40;&#41; &#123; equals&#40;this.mockString, &#34;some string&#34;&#41;; &#125; &#125;&#41;; &#160; test&#40;&#34;Things assigned to this in setup are [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve updated the JS Test Driver <a href="http://code.google.com/p/js-test-driver/wiki/QUnitAdapter">QUnitAdapter</a> to improve compatibility with QUnit.</p>

<p>Variables set on the <code>this</code> object within are now available within setup, teardown, and the tests themselves.</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">module<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Lifecycle'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
  setup<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">mockString</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;some string&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  teardown<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    equals<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">mockString</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;some string&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
test<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Things assigned to this in setup are available in test&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  equals<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">mockString</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;some string&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<p>The <code>test</code> function now supports the optional second parameter of the expected number of assertions.</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// declare that this test has expects 1 assertion</span>
test<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Test with expected defined as 2nd param'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  ok<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<p>My thanks go to <code>anotherhero</code> for providing the <a href="http://code.google.com/p/js-test-driver/issues/detail?id=116">patch</a> to fix both these issues.</p>

<p>You can always <a href="http://code.google.com/p/js-test-driver/wiki/QUnitAdapter">download the latest version of QUnitAdapter from Google Code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://monket.net/blog/2010/04/qunitadapter-1-1-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QUnitAdapter 1.0.3</title>
		<link>http://monket.net/blog/2009/11/qunitadapter-1-0-3/</link>
		<comments>http://monket.net/blog/2009/11/qunitadapter-1-0-3/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 07:32:34 +0000</pubDate>
		<dc:creator>Karl O&#39;Keeffe</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js test driver]]></category>
		<category><![CDATA[qunit]]></category>

		<guid isPermaLink="false">http://monket.net/blog/?p=285</guid>
		<description><![CDATA[Just a small update to the JS Test Driver QUnitAdapter. Version 1.0.3 has been released, and fixes a single bug: Issue 64: QUnit Adapter fails to run tests if you don&#8217;t include a module You can now declare tests without a module, and they will run under the Default Module. In previous versions these tests [...]]]></description>
			<content:encoded><![CDATA[<p>Just a small update to the JS Test Driver <a href="http://code.google.com/p/js-test-driver/wiki/QUnitAdapter">QUnitAdapter</a>. Version 1.0.3 has been released, and fixes a single bug:</p>

<p><strong><a href="http://code.google.com/p/js-test-driver/issues/detail?id=64">Issue 64</a>: QUnit Adapter fails to run tests if you don&#8217;t include a module</strong></p>

<p>You can now declare tests without a module, and they will run under the <code>Default Module</code>. In previous versions these tests would be silently ignored (whoops!).</p>

<p>You can always <a href="http://code.google.com/p/js-test-driver/wiki/QUnitAdapter">download the latest version of QUnitAdapter from Google Code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://monket.net/blog/2009/11/qunitadapter-1-0-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QUnit to JSpec Adapter</title>
		<link>http://monket.net/blog/2009/09/qunit-to-jspec-adapter/</link>
		<comments>http://monket.net/blog/2009/09/qunit-to-jspec-adapter/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 08:07:16 +0000</pubDate>
		<dc:creator>Karl O&#39;Keeffe</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jspec]]></category>
		<category><![CDATA[qunit]]></category>

		<guid isPermaLink="false">http://monket.net/blog/?p=207</guid>
		<description><![CDATA[JSpec is a Javascript BDD framework with a lot of great things going for it: It can run without a browser (great for continuous integration servers), it has a Ruby style custom syntax which makes tests easier to write and read, and it uses a BDD style describe/should syntax. It’s a very tempting framework to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://monket.net/blog/2009/06/new-qunit-to-js-test-driver-adapter/">JSpec</a> is a Javascript BDD framework with a lot of great things going for it: It can run without a browser (great for continuous integration servers), it 
has a Ruby style custom syntax which makes tests easier to write and read, and 
it uses a BDD style describe/should syntax.</p>

<p>It’s a very tempting framework to use, but I already have a large collection
of tests using qunit. I don’t want to use two frameworks for one project, and I 
don’t want to rewrite 300+ tests, so what to do?</p>

<p>How about a QUnit to JSpec Adapter, in the vein of my 
<a href="http://github.com/visionmedia/js-mock-timers/tree/master">QUnit to JS Test Driver Adapter</a>. Just load the adapter into JSpec as a
normal javascript file, and you can now<code>exec()</code> qunit test files in JSpec.</p>

<h2>Downloading the QUnit to JSpec Adapter</h2>

<p>First up <a href="http://monket.net/blog/wp-content/uploads/2009/09/QUnitToJSpecAdapter.js">download the QUnit to JSpec Adapter</a>, or copy the code below, and
save it somewhere in your project (e.g. a <code>lib</code> folder).</p>

<h4><a href="http://monket.net/blog/wp-content/uploads/2009/09/QUnitToJSpecAdapter.js">QUnitToJSpecAdapter.js</a></h4>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*
QUnitToJSpecAdapter
Version: 1.0.0
&nbsp;
Run qunit tests using JSspec
&nbsp;
This provides almost the same api as qunit.
&nbsp;
Tests must run sychronously, which means no use of stop and start methods.
You can use the JSpec mock timers to deal with timeouts, intervals, etc
&nbsp;
The qunit #main DOM element is not included. If you need to do any DOM manipulation
you need to set it up and tear it down in each test.
&nbsp;
*/</span>
<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    JSpec.<span style="color: #660066;">addMatchers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        be_ok <span style="color: #339933;">:</span> <span style="color: #3366CC;">'!!actual'</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    JSpec.<span style="color: #660066;">context</span> <span style="color: #339933;">=</span> JSpec.<span style="color: #660066;">defaultContext</span><span style="color: #339933;">;</span>
    JSpec.<span style="color: #660066;">context</span>.<span style="color: #660066;">QUnitAdapter</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
        modules<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    module <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #339933;">,</span> lifecycle<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        JSpec.<span style="color: #660066;">context</span>.<span style="color: #660066;">QUnitAdapter</span>.<span style="color: #660066;">modules</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #000066;">name</span><span style="color: #339933;">,</span>
            tests<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
            setup<span style="color: #339933;">:</span>    <span style="color: #009900;">&#40;</span>lifecycle <span style="color: #339933;">&amp;&amp;</span> lifecycle.<span style="color: #660066;">setup</span><span style="color: #009900;">&#41;</span>    <span style="color: #339933;">?</span> lifecycle.<span style="color: #660066;">setup</span>    <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> 
            teardown<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>lifecycle <span style="color: #339933;">&amp;&amp;</span> lifecycle.<span style="color: #660066;">teardown</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> lifecycle.<span style="color: #660066;">teardown</span> <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        JSpec.<span style="color: #660066;">describe</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            <span style="color: #003366; font-weight: bold;">var</span> length <span style="color: #339933;">=</span> QUnitAdapter.<span style="color: #660066;">modules</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">tests</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> length<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                it<span style="color: #009900;">&#40;</span>QUnitAdapter.<span style="color: #660066;">modules</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">tests</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #000066;">name</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #003366; font-weight: bold;">var</span> adapter <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
                        expectedAsserts<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
                        calledAsserts<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
&nbsp;
                        expect<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>count<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            adapter.<span style="color: #660066;">expectedAsserts</span> <span style="color: #339933;">=</span> count<span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
                        ok<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>actual<span style="color: #339933;">,</span> msg<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            adapter.<span style="color: #660066;">calledAsserts</span><span style="color: #339933;">++;</span>
                            JSpec.<span style="color: #660066;">expect</span><span style="color: #009900;">&#40;</span>actual<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">to</span><span style="color: #009900;">&#40;</span>JSpec.<span style="color: #660066;">matchers</span>.<span style="color: #660066;">be_ok</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
                        equals<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span> b<span style="color: #339933;">,</span> msg<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            adapter.<span style="color: #660066;">calledAsserts</span><span style="color: #339933;">++;</span>
                            JSpec.<span style="color: #660066;">expect</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">to</span><span style="color: #009900;">&#40;</span>JSpec.<span style="color: #660066;">matchers</span>.<span style="color: #660066;">be</span><span style="color: #339933;">,</span> b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
                        start<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            <span style="color: #000066; font-weight: bold;">throw</span> <span style="color: #3366CC;">'start and stop methods are not available when using JSpec.<span style="color: #000099; font-weight: bold;">\n</span>'</span> <span style="color: #339933;">+</span>
                                <span style="color: #3366CC;">'Use the JSpec timer to deal with timeouts and intervals:<span style="color: #000099; font-weight: bold;">\n</span>'</span> <span style="color: #339933;">+</span> 
                                <span style="color: #3366CC;">'http://github.com/visionmedia/jspec/tree/master'</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
                        <span style="color: #000066;">stop</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            <span style="color: #000066; font-weight: bold;">throw</span> <span style="color: #3366CC;">'start and stop methods are not available when using JSpec.<span style="color: #000099; font-weight: bold;">\n</span>'</span> <span style="color: #339933;">+</span>
                                <span style="color: #3366CC;">'Use the JSpec timer to deal with timeouts and intervals:<span style="color: #000099; font-weight: bold;">\n</span>'</span> <span style="color: #339933;">+</span> 
                                <span style="color: #3366CC;">'http://github.com/visionmedia/jspec/tree/master'</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
                        same<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span> b<span style="color: #339933;">,</span> msg<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            adapter.<span style="color: #660066;">calledAsserts</span><span style="color: #339933;">++;</span>
                            JSpec.<span style="color: #660066;">expect</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">to</span><span style="color: #009900;">&#40;</span>JSpec.<span style="color: #660066;">matchers</span>.<span style="color: #660066;">eql</span><span style="color: #339933;">,</span> b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
                        reset<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            <span style="color: #000066; font-weight: bold;">throw</span> <span style="color: #3366CC;">'reset method is not available when using JSpec'</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
                        isLocal<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span>
                    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #000066; font-weight: bold;">eval</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'with(adapter) {'</span> <span style="color: #339933;">+</span>
                        JSpec.<span style="color: #660066;">contentsOf</span><span style="color: #009900;">&#40;</span>QUnitAdapter.<span style="color: #660066;">modules</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">setup</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span>
                        <span style="color: #3366CC;">'try {'</span> <span style="color: #339933;">+</span>
                        JSpec.<span style="color: #660066;">contentsOf</span><span style="color: #009900;">&#40;</span>QUnitAdapter.<span style="color: #660066;">modules</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">tests</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">testCallback</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span>
                        <span style="color: #3366CC;">'} catch(ex) { throw(ex); } finally {'</span> <span style="color: #339933;">+</span>
                        JSpec.<span style="color: #660066;">contentsOf</span><span style="color: #009900;">&#40;</span>QUnitAdapter.<span style="color: #660066;">modules</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">teardown</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span>
                        <span style="color: #3366CC;">'} }'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>adapter.<span style="color: #660066;">expectedAsserts</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        JSpec.<span style="color: #660066;">expect</span><span style="color: #009900;">&#40;</span>adapter.<span style="color: #660066;">calledAsserts</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">to</span><span style="color: #009900;">&#40;</span>JSpec.<span style="color: #660066;">matchers</span>.<span style="color: #660066;">equal</span><span style="color: #339933;">,</span> adapter.<span style="color: #660066;">expectedAsserts</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            after_each<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                QUnitAdapter.<span style="color: #660066;">modules</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">tests</span>.<span style="color: #660066;">shift</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            after<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                QUnitAdapter.<span style="color: #660066;">modules</span>.<span style="color: #660066;">shift</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    test <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #339933;">,</span> testCallback<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        JSpec.<span style="color: #660066;">context</span>.<span style="color: #660066;">QUnitAdapter</span>.<span style="color: #660066;">modules</span><span style="color: #009900;">&#91;</span>JSpec.<span style="color: #660066;">context</span>.<span style="color: #660066;">QUnitAdapter</span>.<span style="color: #660066;">modules</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">tests</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #000066;">name</span><span style="color: #339933;">,</span>
            testCallback<span style="color: #339933;">:</span> testCallback
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<h2>Having some QUnit tests</h2>

<p>First up you need some qunit tests. Having the qunit test files in the <code>spec</code>
directory helps simplify loading them.</p>

<p>As an example you can use the following:</p>

<h4>qunit-tests.js</h4>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">module<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Examples'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
test<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'True is ok'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  expect<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  ok<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
module<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Examples with lifecycle'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
  setup<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    started <span style="color: #339933;">=</span> <span style="color: #3366CC;">'yes'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  teardown<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    ok<span style="color: #009900;">&#40;</span>started<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    started <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
test<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Test has started'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  expect<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  equals<span style="color: #009900;">&#40;</span>started<span style="color: #339933;">,</span> <span style="color: #3366CC;">'yes'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<h2>Configuring QUnit Support</h2>

<p>Then to enable QUnit tests to be run in JSpec, you must have JSpec load the
adapater as a normal javascript file, and<code>exec()</code> the QUnit test file as you
would a JSpec spec file.</p>

<p>For JSpec rhino support your <code>spec.rhino.js</code> file would look like:</p>

<h4>spec.rhino.js</h4>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">load<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/Library/Ruby/Gems/1.8/gems/visionmedia-jspec-2.10.0/lib/jspec.js'</span><span style="color: #009900;">&#41;</span>
load<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'lib/QUnitAdapter.js'</span><span style="color: #009900;">&#41;</span>
&nbsp;
JSpec
.<span style="color: #660066;">exec</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'spec/qunit-tests.js'</span><span style="color: #009900;">&#41;</span>
.<span style="color: #660066;">run</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> formatter <span style="color: #339933;">:</span> JSpec.<span style="color: #660066;">formatters</span>.<span style="color: #660066;">Terminal</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
.<span style="color: #660066;">report</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></div></div>


<p>Notice how the QUnit test file is exec’d exactly as you would a normal spec
file. You can run specs and Qunit tests along side each other without any 
interference.</p>

<p>And for running the tests within a browser your <code>spec.dom.html</code> file would look
like:</p>

<h4>spec.dom.html</h4>


<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
    &lt;head&gt;
        &lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;/Library/Ruby/Gems/1.8/gems/visionmedia-jspec-2.2.1/lib/jspec.css&quot; /&gt;
        &lt;script src=&quot;/Library/Ruby/Gems/1.8/gems/visionmedia-jspec-2.2.1/lib/jspec.js&quot;&gt;&lt;/script&gt;
        &lt;script src=&quot;../lib/QUnitAdapter.js&quot;&gt;&lt;/script&gt;
        &lt;script&gt;
            function runSuites() {
                JSpec
                .exec('qunit-tests.js')
                .run()
                .report()
            }
        &lt;/script&gt;
    &lt;/head&gt;
    &lt;body class=&quot;jspec&quot; onLoad=&quot;runSuites();&quot;&gt;
        &lt;div id=&quot;jspec-top&quot;&gt;&lt;h2 id=&quot;jspec-title&quot;&gt;JSpec &lt;em&gt;&lt;script&gt;document.write(JSpec.version)&lt;/script&gt;&lt;/em&gt;&lt;/h2&gt;&lt;/div&gt;
        &lt;div id=&quot;jspec&quot;&gt;&lt;/div&gt;
        &lt;div id=&quot;jspec-bottom&quot;&gt;&lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;</pre></div></div>


<h2>Running the tests</h2>

<p>To run the tests just launch JSpec as normal. My prefered method is to run the
tests using rhino, to do this navigate to your project root directory in a 
terminal window and run:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">jspec run <span style="color: #660033;">--rhino</span></pre></div></div>


<p>And you should now see your QUnit tests running in JSpec:</p>


<div class="wp_syntax"><div class="code"><pre class="plain" style="font-family:monospace;"> Passes: 5 Failures: 0
&nbsp;
 Examples
  True is ok..
&nbsp;
 Examples with lifecycle
  Test has started...</pre></div></div>


<h2>Limitations</h2>

<p>This adapter has many of the same limitations and my 
<a href="http://monket.net/blog/2009/06/new-qunit-to-js-test-driver-adapter/">QUnit to JS Test Driver adapter</a>.</p>

<p>The tests must run synchronously (which means no use of the qunit <code>stop</code> and 
<code>start</code> methods).</p>

<p>If you need to test timeouts, intervals, or other asynchronous sections of code
, you can use the<a href="http://github.com/visionmedia/js-mock-timers/tree/master">mock timers that come with JSpec</a>.</p>

<p>QUnit DOM support is not included. Consider avoiding interacting directly with
the browser within your unit tests. But if you do need to, you’ll need to create
and remove the DOM objects yourself with each test, or the setup and teardown 
methods.</p>

<p>And lastly, tests are broken out of any closures before they run. This means
they lose access to any closure variables. For example, the follow test would 
work in QUnit, but not in JSpec. When running in JSpec access to the<code>setup</code>
variable is lost.</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> setup <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// do setup...</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  test<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'name'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://monket.net/blog/2009/09/qunit-to-jspec-adapter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QUnit Adapter 1.0.2</title>
		<link>http://monket.net/blog/2009/08/qunit-adapter-1-0-2/</link>
		<comments>http://monket.net/blog/2009/08/qunit-adapter-1-0-2/#comments</comments>
		<pubDate>Sun, 30 Aug 2009 20:14:51 +0000</pubDate>
		<dc:creator>Karl O&#39;Keeffe</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js test driver]]></category>
		<category><![CDATA[qunit]]></category>

		<guid isPermaLink="false">http://monket.net/blog/?p=203</guid>
		<description><![CDATA[A new version of the JS Test Driver QUnit Adapter is available. Version 1.0.2 fixes a small bug where a module lifecycle object without Setup or Teardown methods would cause a test to error. For example: module&#40;'Lifecycle', &#123;&#125;&#41;; &#160; test&#40;'', function&#40;&#41; &#123; expect&#40;1&#41;; ok&#40;true, 'tests still run successfully even if Setup and Teardown are undefined'&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>A new version of the <a href="http://code.google.com/p/js-test-driver/wiki/QUnitAdapter">JS Test Driver QUnit Adapter</a> is available.</p>

<p>Version 1.0.2 fixes a small bug where a module lifecycle object without Setup or Teardown methods would cause a test to error. For example:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">module<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Lifecycle'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
test<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	expect<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	ok<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'tests still run successfully even if Setup and Teardown are undefined'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<p>Would give the error <code>Lifecycle.test  error (1.00 ms): Result of expression 'l.setUp' [undefined] is not a function.</code>.</p>

<p>This is now fixed so the test behaves as if no lifecycle was defined.</p>

<p>You can get the new <a href="http://code.google.com/p/js-test-driver/wiki/QUnitAdapter">1.0.2 verison of the QUnit Adapter from Google Code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://monket.net/blog/2009/08/qunit-adapter-1-0-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Update to QUnit Adapter</title>
		<link>http://monket.net/blog/2009/07/update-to-qunit-adapter/</link>
		<comments>http://monket.net/blog/2009/07/update-to-qunit-adapter/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 06:32:25 +0000</pubDate>
		<dc:creator>Karl O&#39;Keeffe</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js test driver]]></category>
		<category><![CDATA[qunit]]></category>

		<guid isPermaLink="false">http://monket.net/blog/?p=154</guid>
		<description><![CDATA[I&#8217;ve made a small update to the QUnit Adapter for JS Test Driver. This fixes a bug where the ok() assertion was much stricter than the qunit equivalent. It was only succeeding when passed a boolean true value. Now it behaves the same as the qunit version, and succeeds with all values other than 0, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve made a small update to the <a href="http://code.google.com/p/js-test-driver/wiki/QUnitAdapter">QUnit Adapter for JS Test Driver</a>.</p>

<p>This fixes a bug where the <code>ok()</code> assertion was much stricter than the qunit equivalent. It was only succeeding when passed a boolean <code>true</code> value.</p>

<p>Now it behaves the same as the qunit version, and succeeds with all values other than <code>0</code>, <code>false</code>, or <code>null</code>.</p>

<p>You can get the new <a href="http://code.google.com/p/js-test-driver/wiki/QUnitAdapter">1.0.1 verison of the QUnit Adapter from Google Code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://monket.net/blog/2009/07/update-to-qunit-adapter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QUnitAdapter now part of JS Test Driver</title>
		<link>http://monket.net/blog/2009/07/qunitadapter-now-part-of-js-test-driver/</link>
		<comments>http://monket.net/blog/2009/07/qunitadapter-now-part-of-js-test-driver/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 07:54:25 +0000</pubDate>
		<dc:creator>Karl O&#39;Keeffe</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js test driver]]></category>
		<category><![CDATA[qunit]]></category>

		<guid isPermaLink="false">http://monket.net/blog/?p=133</guid>
		<description><![CDATA[In my last post I introduced a QUnit to JS Test Driver adapter, a small adapter which converts QUnit tests into native JS Test Driver tests. This adapter is now part of the JS Test Driver project. There is now a QUnit Adapter wiki page on the JS Test Driver project site. This will be [...]]]></description>
			<content:encoded><![CDATA[<p>In my last post I <a href="http://monket.net/blog/2009/06/new-qunit-to-js-test-driver-adapter/">introduced a QUnit to JS Test Driver adapter</a>, a small adapter which converts QUnit tests into native JS Test Driver tests.</p>

<p>This adapter is now part of the JS Test Driver project.</p>

<p>There is now a <a href="http://code.google.com/p/js-test-driver/wiki/QUnitAdapter">QUnit Adapter wiki page</a> on the JS Test Driver project site. This will be updated to keep up with any changes to the adapter.</p>

<p>The code is now stored within the JS Test Driver subversion repository. You can always <a href="http://code.google.com/p/js-test-driver/source/browse/#svn/trunk/JsTestDriver/contrib/qunit">download the latest version of the QUnit Adapter</a> using the Google Code web interface.</p>

<p>Thanks to Jeremie Lenfant-engelmann for deeming QUnit Adapter worthy of official regonition :)</p>
]]></content:encoded>
			<wfw:commentRss>http://monket.net/blog/2009/07/qunitadapter-now-part-of-js-test-driver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New QUnit to JS Test Driver adapter</title>
		<link>http://monket.net/blog/2009/06/new-qunit-to-js-test-driver-adapter/</link>
		<comments>http://monket.net/blog/2009/06/new-qunit-to-js-test-driver-adapter/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 07:56:28 +0000</pubDate>
		<dc:creator>Karl O&#39;Keeffe</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js test driver]]></category>
		<category><![CDATA[qunit]]></category>

		<guid isPermaLink="false">http://monket.net/blog/?p=104</guid>
		<description><![CDATA[The code in this post is out of date. The latest code can always be found in the JS Test Driver google code site In my previous post on QUnit and JS Test Driver I showed how to run your qunit tests with JS Test Driver. The technique used was to run the tests with [...]]]></description>
			<content:encoded><![CDATA[<div class="info">The code in this post is out of date. The latest code can always be found in the <a href="http://code.google.com/p/js-test-driver/wiki/QUnitAdapter">JS Test Driver google code site</a></div>

<p>In my <a href="http://monket.net/blog/2009/06/qunit-and-js-test-driver/">previous post on QUnit and JS Test Driver</a> I showed how to run your <a href="http://docs.jquery.com/QUnit">qunit</a> tests with <a href="http://code.google.com/p/js-test-driver/">JS Test Driver</a>.</p>

<p>The technique used was to run the tests with qunit, and report either their success or failure to JS Test Driver. This works, but you miss out on the important feedback of exactly which assertions have failed, and why.</p>

<p>This problem has led me to taking a new approach to running qunit tests with JS Test Driver, where I don&#8217;t use any of the existing qunit code, and instead just create an interface wrapper that converts qunit style tests and assertions directly into JS Test Driver tests and assertions.</p>

<p>This gives assertion level error reporting, making it much easier to write and debug tests. Essentially this adapter allows you to write native JS Test Driver tests, but using the less verbose qunit syntax.</p>

<p>The new approach also means that qunit lifecycles (setup and teardown) work.</p>

<h2>Installing the QUnit Adapter</h2>

<p>First up download the <a href='http://monket.net/blog/wp-content/uploads/2009/06/equiv.js'>equiv.js</a> file, which is required for the qunit <code>same</code> assertion.</p>

<p>Then download the <a href='http://monket.net/blog/wp-content/uploads/2009/06/QUnitAdapter.js'>QUnitAdapter.js</a> file (or copy the code below).</p>

<h4><a href='http://monket.net/blog/wp-content/uploads/2009/06/QUnitAdapter.js'>QUnitAdapter.js</a></h4>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    window.<span style="color: #660066;">module</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #339933;">,</span> lifecycle<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        QUnitTestCase <span style="color: #339933;">=</span> TestCase<span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>lifecycle<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            QUnitTestCase.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">setUp</span> <span style="color: #339933;">=</span> lifecycle.<span style="color: #660066;">setup</span><span style="color: #339933;">;</span>
            QUnitTestCase.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">tearDown</span> <span style="color: #339933;">=</span> lifecycle.<span style="color: #660066;">teardown</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    window.<span style="color: #660066;">test</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #339933;">,</span> test<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        QUnitTestCase.<span style="color: #660066;">prototype</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'test '</span> <span style="color: #339933;">+</span> <span style="color: #000066;">name</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> test<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    window.<span style="color: #660066;">expect</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>count<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        expectAsserts<span style="color: #009900;">&#40;</span>count<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    window.<span style="color: #660066;">ok</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>actual<span style="color: #339933;">,</span> msg<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        assertTrue<span style="color: #009900;">&#40;</span>msg <span style="color: #339933;">?</span> msg <span style="color: #339933;">:</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">,</span> actual<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    window.<span style="color: #660066;">equals</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span> b<span style="color: #339933;">,</span> msg<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        assertEquals<span style="color: #009900;">&#40;</span>msg <span style="color: #339933;">?</span> msg <span style="color: #339933;">:</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">,</span> b<span style="color: #339933;">,</span> a<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    window.<span style="color: #660066;">start</span> <span style="color: #339933;">=</span> window.<span style="color: #000066;">stop</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        fail<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'start and stop methods are not available when using JS Test Driver.<span style="color: #000099; font-weight: bold;">\n</span>'</span> <span style="color: #339933;">+</span>
            <span style="color: #3366CC;">'Use jsUnit Clock object to deal with timeouts and intervals:<span style="color: #000099; font-weight: bold;">\n</span>'</span> <span style="color: #339933;">+</span> 
            <span style="color: #3366CC;">'http://googletesting.blogspot.com/2007/03/javascript-simulating-time-in-jsunit.html.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    window.<span style="color: #660066;">same</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span> b<span style="color: #339933;">,</span> msg<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        assertTrue<span style="color: #009900;">&#40;</span>msg <span style="color: #339933;">?</span> msg <span style="color: #339933;">:</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">,</span> window.<span style="color: #660066;">equiv</span><span style="color: #009900;">&#40;</span>b<span style="color: #339933;">,</span> a<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    window.<span style="color: #660066;">reset</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    	fail<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'reset method is not available when using JS Test Driver'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    window.<span style="color: #660066;">isLocal</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    window.<span style="color: #660066;">QUnit</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    	equiv<span style="color: #339933;">:</span> window.<span style="color: #660066;">equiv</span><span style="color: #339933;">,</span>
    	ok<span style="color: #339933;">:</span> window.<span style="color: #660066;">ok</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<p>Save both these files to your project (for example <code>tests/qunit/</code>).</p>

<h2>Configuring JS Test Driver</h2>

<p>To run your qunit tests in JS Test Driver you need to configure it to load the adapter before your qunit tests.</p>

<p>Update your <code>jsTestDriver.conf</code> to load the files:</p>


<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">server: http://localhost:9876
&nbsp;
load:
  # Add these lines to load the equiv function and adapter in order, before the tests
  # (assuming they are saved to tests/qunit/)
  - tests/qunit/equiv.js
  - tests/qunit/QUnitAdapter.js
&nbsp;
  # This is where we load the qunit tests
  - tests/js/*.js
&nbsp;
  # And this loads the source files we are testing
  - src/js/*.js</pre></div></div>


<h2>Running JS Test Driver with qunit tests</h2>

<p>Now we can run JS Test Driver and watch as it runs all our qunit tests!</p>

<p>The tests will run as individual JS Test Driver tests, with the format <code><em>Module Name</em>.<em>Test Name</em></code>.</p>

<p>Example output:</p>


<div class="wp_syntax"><div class="code"><pre class="none" style="font-family:monospace;">[PASSED] Module 1.test Test 1
[PASSED] Module 1.test Test 2
[PASSED] Module 2.test Test 1
Total 3 tests (Passed: 3; Fails: 0; Errors: 0) (1.00 ms)
  Safari 530.18: Run 3 tests (Passed: 3; Fails: 0; Errors 0) (1.00 ms)</pre></div></div>


<h2>Limitations</h2>

<p>There are a few limitations on which qunit tests will successfully be converted.</p>

<p>The tests must run synchronously (which means no use of the qunit <code>stop</code> and <code>start</code> methods).</p>

<p>If you need to test timeouts, intervals, or other asynchronous sections of  code, consider <a href="http://googletesting.blogspot.com/2007/03/javascript-simulating-time-in-jsunit.html">using the jsUnit Clock object to deal with timeouts and intervals.</a></p>

<p>QUnit <code>DOM</code> support is not included. Consider avoiding interacting directly with the browser within your unit tests. But if you do need to, you&#8217;ll need to create and remove the DOM objects yourself with each test, or the <code>setup</code> and <code>teardown</code> methods.</p>
]]></content:encoded>
			<wfw:commentRss>http://monket.net/blog/2009/06/new-qunit-to-js-test-driver-adapter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QUnit and JS Test Driver</title>
		<link>http://monket.net/blog/2009/06/qunit-and-js-test-driver/</link>
		<comments>http://monket.net/blog/2009/06/qunit-and-js-test-driver/#comments</comments>
		<pubDate>Sun, 21 Jun 2009 17:18:04 +0000</pubDate>
		<dc:creator>Karl O&#39;Keeffe</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js test driver]]></category>
		<category><![CDATA[qunit]]></category>

		<guid isPermaLink="false">http://monket.net/blog/?p=84</guid>
		<description><![CDATA[This post has obsoleted been the new QUnit Adapter I created, check it out! I was very impressed by the new Google JS Test Driver project, which provides a blisteringly fast, and easily automated way of running your Javascript unit tests. See this introduction to JS Test Driver by Miško Hevery for a great overview. [...]]]></description>
			<content:encoded><![CDATA[<div class="info">This post has obsoleted been the <a href="http://code.google.com/p/js-test-driver/wiki/QUnitAdapter">new QUnit Adapter</a> I created, check it out!</div>

<p>I was very impressed by the new Google <a href="http://code.google.com/p/js-test-driver/">JS Test Driver</a> project, which provides a blisteringly fast, and easily automated way of running your Javascript unit tests. See this <a href="http://misko.hevery.com/2009/05/22/yet-another-javascript-testing-framework/">introduction to JS Test Driver by Miško Hevery</a> for a great overview.</p>

<p>I previously described how to <a href="http://monket.net/blog/2009/06/autotest-and-js-test-driver/">run JS Test Driver automatically with Autotest</a>.</p>

<p>But I have an existing project that uses the jQuery testing framework <a href="http://docs.jquery.com/QUnit">qunit</a> for testing. I didn&#8217;t really fancy rewriting 300+ tests just so I could use the JS Test Driver framework.</p>

<p>So I wrote a converter that automatically converts qunit modules and tests into JS Test Driver TestCases and test methods.</p>

<h2>Download Converter and Patched Testrunner</h2>

<p>In order to convert from qunit tests I&#8217;ve had to add a few extra hooks into the qunit <code>testrunner.js</code> file.</p>

<p>Either <a href='http://monket.net/blog/wp-content/uploads/2009/06/testrunner.js'>download the patched testrunner.js</a> file, or just add the 3 lines below:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>234
235
236
237
238
239
240
241
242
243
244
245
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">    QUnit<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// Add the following 3 lines </span>
        runTest<span style="color: #339933;">:</span> runTest<span style="color: #339933;">,</span>
        config<span style="color: #339933;">:</span> config<span style="color: #339933;">,</span>
        validTest<span style="color: #339933;">:</span> validTest<span style="color: #339933;">,</span>	
&nbsp;
        <span style="color: #006600; font-style: italic;">// This is existing code	</span>
        equiv<span style="color: #339933;">:</span> equiv<span style="color: #339933;">,</span>
        ok<span style="color: #339933;">:</span> ok<span style="color: #339933;">,</span>
        done<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>failures<span style="color: #339933;">,</span> total<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        log<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>result<span style="color: #339933;">,</span> message<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span></pre></td></tr></table></div>


<p>Next <a href='http://monket.net/blog/wp-content/uploads/2009/06/QUnitToTestCases.js'>download QUnitToTestCases.js</a> and save it to the same folder as <code>testrunner.js</code>. This is the file which converts the qunit tests into TestCases that JS Test Driver understands.</p>

<p>It works by overriding the qunit <code>test()</code> function, and rather than adding the test to qunit, it creates a test method on a TestCase object which, when called by JS Test Driver adds the test to qunit and runs it.</p>

<h2>Configuring JS Test Driver</h2>

<p>Once you have the patched <code>testrunner.js</code> and <code>QUnitToTestCases.js</code>, you just need to let JS Test Driver know to load them before your qunit tests. They need to be loaded in order, with  <code>testrunner.js</code> first, followed by <code>QUnitTiTestCases.js</code>, as the converter modifies some of the testrunner methods.</p>

<p>Update your <code>jsTestDriver.conf</code> to load the files:</p>


<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">server: http://localhost:9876
&nbsp;
load:
  # Add these lines to load the testrunner and converter in order, before the tests
  # (assuming the files are saved to tests/qunit/)
  - tests/qunit/testrunner.js
  - tests/qunit/QUnitToTestCases.js
&nbsp;
  # This is where we load the qunit tests
  - tests/js/*.js
&nbsp;
  # And this loads the source files we are testing
  - src/js/*.js</pre></div></div>


<h2>Running JS Test Driver with qunit tests</h2>

<p>Now we can run JS Test Driver and watch as it runs all our qunit tests!</p>

<p>The tests will run as individual JS Test Driver tests, with the format <code><em>Module Name</em>.<em>Test Name</em></code>.</p>

<p>Example output:</p>


<div class="wp_syntax"><div class="code"><pre class="none" style="font-family:monospace;">[PASSED] Module 1.test Test 1
[PASSED] Module 1.test Test 2
[PASSED] Module 2.test Test 1
Total 3 tests (Passed: 3; Fails: 0; Errors: 0) (1.00 ms)
  Safari 530.18: Run 3 tests (Passed: 3; Fails: 0; Errors 0) (1.00 ms)</pre></div></div>


<h2>Limitations</h2>

<p>There are a few limitations on which qunit tests will successfully be converted.</p>

<p>The tests must run synchronously (which means no use of the qunit <code>stop</code> and <code>start</code> methods).</p>

<p>Module lifecycles are ignored at the moment, which means <code>setup</code> and <code>teardown</code> functions are not called.</p>
]]></content:encoded>
			<wfw:commentRss>http://monket.net/blog/2009/06/qunit-and-js-test-driver/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

