<?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; jsunit</title>
	<atom:link href="http://monket.net/blog/tag/jsunit/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>jsUnit Mock Timeouts and JS Test Driver</title>
		<link>http://monket.net/blog/2009/07/jsunit-mock-timeouts-and-js-test-driver/</link>
		<comments>http://monket.net/blog/2009/07/jsunit-mock-timeouts-and-js-test-driver/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 16:45:30 +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[jsunit]]></category>

		<guid isPermaLink="false">http://monket.net/blog/?p=139</guid>
		<description><![CDATA[As part of my experimenting with JS Test Driver, I have been porting over a suite of about 300 existing tests. Some of these tests deal with time based logic, such as delayed callbacks or time limited user interaction. Currently these tests are run in a HTML page using qunit. To deal with the time [...]]]></description>
			<content:encoded><![CDATA[<p>As part of my experimenting with <a href="http://code.google.com/p/js-test-driver/">JS Test Driver</a>, I have been porting over a suite of about 300 existing tests.</p>

<p>Some of these tests deal with time based logic, such as delayed callbacks or time limited user interaction. Currently these tests are run in a HTML page using <a href="http://docs.jquery.com/QUnit">qunit</a>.</p>

<p>To deal with the time based logic I use the jsUnit&#8217;s Mock Timeout. See <a href="http://googletesting.blogspot.com/2007/03/javascript-simulating-time-in-jsunit.html">Simulating Time in jsUnit Tests on the Google Testing Blog</a>.</p>

<p>jsUnit&#8217;s Mock Timeout overrides the built in <code>setTimeout</code>, <code>clearTimeout</code>, <code>setInterval</code>, and <code>clearInterval</code> methods, and provides a <code>Clock</code> object that allows you to control the passage of time.</p>

<h2>Problem</h2>

<p>This works fine in qunit, but it fails catastrophically in JS Test Driver. This is because JS Test Driver uses the <code>setTimeout</code> and <code>setInterval</code> methods to control it&#8217;s own behaviour. Once these have been overridden with the mock versions JS Test Driver no longer works.</p>

<p>As a temporary fix for this I have created a patched version of JS Test Driver, which creates it&#8217;s own copies of the original <code>setTimeout</code>, <code>clearTimeout</code>, <code>setInterval</code>, and <code>clearInterval</code> methods, before loading any code. This ensures it works well with the jsUnit Mock Timeout.</p>

<h2>Patched JS Test Driver</h2>

<p><a href="http://monket.net/blog/wp-content/uploads/2009/07/JsTestDriver-1.0b-own-timeouts.jar">Download a patched JsTestDriver with no-confilict timeouts.</a></p>

<p>Just use this jar in place of the original <code>JsTestDriver-1.0b.jar</code>, and you can include <code>jsUnitMockTimeout.js</code> in your tests without breaking JS Test Driver!</p>

<p>You may also want to <a href="http://monket.net/blog/wp-content/uploads/2009/07/jsUnitMockTimeout.js">download jsUnitMockTimeout.js</a> (to save you finding it within the jsUnit source).</p>

<h2>The Future</h2>

<p>I see this patched JS Test Driver as very much a temporary stepping stone, while the correct solution is worked out. Beware of relying on it too heavily!</p>

<div class="info">

<p><strong>Update</strong>: <a href="http://groups.google.com/group/js-test-driver/browse_thread/thread/1393946af440ed90/c532267cd6c90710#c532267cd6c90710">This solution has been integrated into JS Test Driver</a>, and will be available in the next release.</p>

</div>
]]></content:encoded>
			<wfw:commentRss>http://monket.net/blog/2009/07/jsunit-mock-timeouts-and-js-test-driver/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

