Thursday, December 18th, 2008
FireUnit: JavaScript Unit Testing Extension
John Resig and Jan Odvarko have announced something pretty darn cool, FireUnit.
![]()
FireUnit provides a simple JavaScript API for doing simple test logging and viewing within a new tab of Firebug.
The example given shows the API nicely:
-
-
// Simple true-like/false-like testing
-
fireunit.ok( true, "I'm going to pass!" );
-
fireunit.ok( false, "I'm going to fail!" );
-
-
// Compare two strings - shows a diff of the
-
// results if they're different
-
fireunit.compare(
-
"The lazy fox jumped over the log.",
-
"The lazy brown fox jumped the log.",
-
"Are these two strings the same?"
-
);
-
-
// Compare a string using a regular expression
-
fireunit.reCompare(
-
/The .* fox jumped the log./,
-
"The lazy brown fox jumped the log.",
-
"Compare a string using a RegExp."
-
);
-
-
// Display the total results
-
fireunit.testDone();
-
-
// -- browser events
-
-
// You can also simulate browser events
-
var input = document.getElementsByTagName("input")[0];
-
fireunit.mouseDown( input );
-
fireunit.click( input );
-
fireunit.focus( input );
-
fireunit.key( input, "a" );
-
-
// -- Run batches
-
-
// Or run multiple pages of tests:
-
fireunit.runTests("test2.html", "test3.html");
-
-
// Place at the end of every test file in order to continue
-
fireunit.testDone();
-












It would have be really cool if it had extended the console object instead of using a new one. Imagine this thing ported to every browser already implementing “console”. Life would be way easier.
This broke my firebug. I had to uninstall fire unit to get it back.
Running FF 2.0.0.19, FB: 1.05
@cgishack: If you read the text next to the download link you’ll see why.
@tj111 Oh yes.. thanks.
Looks nice, especially the event firing stuff. I think I will stick with JSSpec for testing my JavaScipt models, but this will be good for testing the DOM dependent views.
Any chance this could be made to work with Firebug lite so we could run our test suite in other browsers?