<?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>Meatball&#039;s Guide to .NET &#187; qUnit</title>
	<atom:link href="http://rogerpence.com/blog/index.php/archives/tag/qunit/feed" rel="self" type="application/rss+xml" />
	<link>http://rogerpence.com/blog</link>
	<description>A dogma-free guide to making real-world sense of .NET</description>
	<lastBuildDate>Wed, 23 Jun 2010 16:15:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Avoid non-FireFox browser issues with Firebug&#8217;s console object</title>
		<link>http://rogerpence.com/blog/index.php/archives/319</link>
		<comments>http://rogerpence.com/blog/index.php/archives/319#comments</comments>
		<pubDate>Thu, 21 Jan 2010 15:57:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Firebug]]></category>
		<category><![CDATA[qUnit]]></category>

		<guid isPermaLink="false">http://rogerpence.com/blog/?p=319</guid>
		<description><![CDATA[The Firefox Firebug add-in is a superb JavaScript debugger. If you’re writing, learning, or debugging JavaScript (and if you’re doing the first two, you’re certainly doing the third!), Firebug should be in the top drawer of your JavaScript toolbox. 
One of the Firebug features I use a lot is its console object. The console object [...]]]></description>
			<content:encoded><![CDATA[<p>The Firefox <a href="http://getfirebug.com/index.html">Firebug</a> add-in is a superb JavaScript debugger. If you’re writing, learning, or debugging JavaScript (and if you’re doing the first two, you’re certainly doing the third!), Firebug should be in the top drawer of your JavaScript toolbox. </p>
<p>One of the Firebug features I use a lot is its <a href="http://getfirebug.com/console.html">console object</a>. The console object lets you emit messages from your code to Firebug’s console. For example, <em>console.log( n );</em> emits informational message <em>n</em> to the Firebug console while <em>console.error(n);</em> emits error message <em>n</em> to the Firebug console. This console is very handy, especially in your JavaScript unit testing code. While Firebug doesn’t have a steep learning curve, some of its features can sneak up on you. If you haven’t yet dug into Firebug’s console, do so soon! </p>
<p>A challenge that the Firebug console presents is that to use it requires that you pepper your code with Firebug-specific code that will cause the code to break in other non-Firefox browsers. For production work, you’ll probably want to comment out or remove <em>console</em> lines.&#160; However, I want to run my JavaScript unit tests in several browsers and don’t want to have to change the test code to do so. </p>
<p>Firebug’s creator, <a href="http://www.joehewitt.com/about.php">Joe Hewitt</a>, posted a nice little <a href="http://code.google.com/p/fbug/source/browse/branches/firebug1.2/lite/firebugx.js?r=964">chunk of code</a> (shown below) that maps Firebug’s various console methods to no-ops for non-FIreFox browsers. With Joe’s code in place, JavaScript tests can run in any browser. For <a href="http://docs.jquery.com/QUnit">qUnit</a> JavaScript unit testing code, add Joe’s code to the module’s setup method (more on qUnit in an upcoming post). </p>
<div class="sourceCodeHeading">Joe Hewitt’s prophylactic Firebug console code</div>
<div id="Id1009557102SourceCode" class="sourceCode">
<pre class="even"><span class="ln">  1</span><span class="code">if (!window.console || !console.firebug)</span></pre>
<pre class="odd"><span class="ln">  2</span><span class="code">{</span></pre>
<pre class="even"><span class="ln">  3</span><span class="code">    var names = [&quot;log&quot;, &quot;debug&quot;, &quot;info&quot;, &quot;warn&quot;, &quot;error&quot;, &quot;assert&quot;, &quot;dir&quot;, &quot;dirxml&quot;,</span></pre>
<pre class="odd"><span class="ln">  4</span><span class="code">    &quot;group&quot;, &quot;groupEnd&quot;, &quot;time&quot;, &quot;timeEnd&quot;, &quot;count&quot;, &quot;trace&quot;, &quot;profile&quot;, &quot;profileEnd&quot;];</span></pre>
<pre class="even"><span class="ln">  5</span><span class="code"></span></pre>
<pre class="odd"><span class="ln">  6</span><span class="code">    window.console = {};</span></pre>
<pre class="even"><span class="ln">  7</span><span class="code">    for (var i = 0; i &lt; names.length; ++i)</span></pre>
<pre class="odd"><span class="ln">  8</span><span class="code">        window.console[names[i]] = function() {}</span></pre>
<pre class="even"><span class="ln">  9</span><span class="code">}</span></pre>
</div>
<div class="sourceCodeFooter"><a id="Id1009557102SourceCodeToClipboard" class="copyLink" href="javascript:toggleLineNumbers( 'Id1009557102SourceCode' );">Show copy-friendly code</a></div>
<p><em>One final note: </em>I occasionally teach JavaScript. Joe’s graceful little solution to the awkward cross-browser problem posed by using Firebug’s <em>console </em>object makes a great little quiz for JavaScript beginners. It’s not a lot of code, but what little code there is is interesting code. When someone can explain Joe’s code clearly, I know they are ready for the next notch in their JavaScript programming belt. </p>
]]></content:encoded>
			<wfw:commentRss>http://rogerpence.com/blog/index.php/archives/319/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
