diff options
Diffstat (limited to 'tests/unit/testsuite.js')
-rw-r--r-- | tests/unit/testsuite.js | 110 |
1 files changed, 91 insertions, 19 deletions
diff --git a/tests/unit/testsuite.js b/tests/unit/testsuite.js index d37e27f7b..33a9a2c99 100644 --- a/tests/unit/testsuite.js +++ b/tests/unit/testsuite.js @@ -1,4 +1,75 @@ -(function() { +(function( $ ) { + +window.TestHelpers = {}; + +function includeStyle( url ) { + document.write( "<link rel='stylesheet' href='../../../" + url + "'>" ); +} + +function includeScript( url ) { + document.write( "<script src='../../../" + url + "'></script>" ); +} + +QUnit.config.urlConfig.push( "min" ); +TestHelpers.loadResources = QUnit.urlParams.min ? + function() { + // TODO: proper include with theme images + includeStyle( "dist/jquery-ui.min.css" ); + includeScript( "dist/jquery-ui.min.js" ); + } : + function( resources ) { + $.each( resources.css || [], function( i, resource ) { + includeStyle( "themes/base/jquery." + resource + ".css" ); + }); + $.each( resources.js || [], function( i, resource ) { + includeScript( resource ); + }); + }; + +QUnit.config.urlConfig.push( "nojshint" ); +var jshintLoaded = false; +TestHelpers.testJshint = function( module ) { + if ( QUnit.urlParams.nojshint ) { + return; + } + + if ( !jshintLoaded ) { + includeScript( "external/jshint.js" ); + jshintLoaded = true; + } + + asyncTest( "JSHint", function() { + expect( 1 ); + + $.when( + $.ajax({ + url: "../../../ui/.jshintrc", + dataType: "json" + }), + $.ajax({ + url: "../../../ui/jquery." + module + ".js", + dataType: "text" + }) + ).done(function( hintArgs, srcArgs ) { + var passed = JSHINT( srcArgs[ 0 ], hintArgs[ 0 ] ), + errors = $.map( JSHINT.errors, function( error ) { + // JSHINT may report null if there are too many errors + if ( !error ) { + return; + } + + return "[L" + error.line + ":C" + error.character + "] " + + error.reason + "\n" + error.evidence + "\n"; + }).join( "\n" ); + ok( passed, errors ); + start(); + }) + .fail(function() { + ok( false, "error loading source" ); + start(); + }); + }); +}; function testWidgetDefaults( widget, defaults ) { var pluginDefaults = $.ui[ widget ].prototype.options; @@ -22,17 +93,15 @@ function testWidgetDefaults( widget, defaults ) { }); } -var privateMethods = [ - "_createWidget", - "destroy", - "option", - "_trigger" -]; - function testWidgetOverrides( widget ) { if ( $.uiBackCompat === false ) { test( "$.widget overrides", function() { - $.each( privateMethods, function( i, method ) { + $.each([ + "_createWidget", + "destroy", + "option", + "_trigger" + ], function( i, method ) { strictEqual( $.ui[ widget ].prototype[ method ], $.Widget.prototype[ method ], "should not override " + method ); }); @@ -54,16 +123,17 @@ function testBasicUsage( widget ) { }); } -window.commonWidgetTests = function( widget, settings ) { +TestHelpers.commonWidgetTests = function( widget, settings ) { module( widget + ": common widget" ); + TestHelpers.testJshint( "ui." + widget ); testWidgetDefaults( widget, settings.defaults ); testWidgetOverrides( widget ); testBasicUsage( widget ); test( "version", function() { ok( "version" in $.ui[ widget ].prototype, "version property exists" ); }); -} +}; /* * Experimental assertion for comparing DOM objects. @@ -72,20 +142,22 @@ window.commonWidgetTests = function( widget, settings ) { * Then compares the result using deepEqual. */ window.domEqual = function( selector, modifier, message ) { - var attributes = ["class", "role", "id", "tabIndex", "aria-activedescendant"]; + var expected, actual, + attributes = ["class", "role", "id", "tabIndex", "aria-activedescendant"]; function extract(value) { if (!value || !value.length) { QUnit.push( false, actual, expected, "domEqual failed, can't extract " + selector + ", message was: " + message ); return; } - var result = {}; + var children, + result = {}; result.nodeName = value[0].nodeName; $.each(attributes, function(index, attr) { result[attr] = value.prop(attr); }); result.children = []; - var children = value.children(); + children = value.children(); if (children.length) { children.each(function() { result.children.push(extract($(this))); @@ -95,11 +167,11 @@ window.domEqual = function( selector, modifier, message ) { } return result; } - var expected = extract($(selector)); - modifier($(selector)); + expected = extract( $( selector ) ); + modifier( $( selector ) ); - var actual = extract($(selector)); + actual = extract( $( selector ) ); QUnit.push( QUnit.equiv(actual, expected), actual, expected, message ); -} +}; -}()); +}( jQuery )); |