Tobias Ebnöther's personal blog

YUI3 Test and JsTestDriver

As some of you might know I am a big fan of YUI3. Currently I am revamping the JavaScript tests at local.ch which uses YUI3 for all the new stuff we do. I found some code from lazr and modified it a little to match my taste better. So basically all you do is include that snipped:

YUI.add('jstestdriver', function(Y) {
    R = Y.namespace('jstestdriver.Runner');

    R.add = function add(suite) {
            if ((typeof jstestdriver === "undefined")) {
                // If we are not running under JsTestDriver, then
                // register the suite with Y.Test.Runner and run it.

            } else {
                // If ``jstestdriver`` is defined, that means we are
                // running under JsTestDriver, so instead register each
                // test case from the suite as a separate TestCase() with
                // JsTestDriver.
                for each(var test_case in suite.items) {
                    TestCase(test_case.name, test_case);

    R.run = function run(suite) {
            if ((typeof jstestdriver === "undefined")) {
                // If we are not running under JsTestDriver, then run all
                // the registered test suites with Y.Test.Runner.
                var yconsole = new Y.Console({
                    newestOnTop: false
'0.1', {
    requires: ['test', 'console']

Now you can write your tests as usual you only need to to the assigning a bit different. Instead of the normal YUI3 Test Runner you use this:


What you have to watch out for: Load _ALL_ Yahoo code with your tests otherwise you will have very funky side effects of tests not running the first time but passing the second one, when yui3 loaded the missing files. I created one big file including everything that I use for that purpose.

Comments (6)  Permalink
Powered by Flux CMS