test runner: the changes are:

- Replaced all the $ for jQuery in the tests and suite.
- Added a noConflict to testrunner.js.
- Modified the test for noConflict() so that it still work.
- Added jQuery 1.2.1 and 1.2.3 to otherlibs.
This commit is contained in:
Ariel Flesler 2008-05-28 23:18:25 +00:00
parent abb055bb49
commit 9e48649729
11 changed files with 856 additions and 830 deletions

View file

@ -1,3 +1,5 @@
jQuery.noConflict(); // Allow the test to run with other libs or jQuery's.
var _config = { var _config = {
fixture: null, fixture: null,
Test: [], Test: [],
@ -14,12 +16,12 @@ var _config = {
}; };
_config.filters = location.search.length > 1 && //restrict modules/tests by get parameters _config.filters = location.search.length > 1 && //restrict modules/tests by get parameters
$.map( location.search.slice(1).split('&'), decodeURIComponent ); jQuery.map( location.search.slice(1).split('&'), decodeURIComponent );
var isLocal = !!(window.location.protocol == 'file:'); var isLocal = !!(window.location.protocol == 'file:');
$(function() { jQuery(function() {
$('#userAgent').html(navigator.userAgent); jQuery('#userAgent').html(navigator.userAgent);
runTest(); runTest();
}); });
@ -81,15 +83,15 @@ function runTest() {
_config.blocking = false; _config.blocking = false;
var time = new Date(); var time = new Date();
_config.fixture = document.getElementById('main').innerHTML; _config.fixture = document.getElementById('main').innerHTML;
_config.ajaxSettings = $.ajaxSettings; _config.ajaxSettings = jQuery.ajaxSettings;
synchronize(function() { synchronize(function() {
time = new Date() - time; time = new Date() - time;
$("<div>").html(['<p class="result">Tests completed in ', jQuery("<div>").html(['<p class="result">Tests completed in ',
time, ' milliseconds.<br/>', time, ' milliseconds.<br/>',
_config.stats.bad, ' tests of ', _config.stats.all, ' failed.</p>'] _config.stats.bad, ' tests of ', _config.stats.all, ' failed.</p>']
.join('')) .join(''))
.appendTo("body"); .appendTo("body");
$("#banner").addClass(_config.stats.bad ? "fail" : "pass"); jQuery("#banner").addClass(_config.stats.bad ? "fail" : "pass");
}); });
} }
@ -154,11 +156,11 @@ function test(name, callback, nowait) {
else else
n.style.display = "none"; n.style.display = "none";
}; };
$(b).dblclick(function(event) { jQuery(b).dblclick(function(event) {
var target = jQuery(event.target).filter("strong").clone(); var target = jQuery(event.target).filter("strong").clone();
if ( target.length ) { if ( target.length ) {
target.children().remove(); target.children().remove();
location.href = location.href.match(/^(.+?)(\?.*)?$/)[1] + "?" + encodeURIComponent($.trim(target.text())); location.href = location.href.match(/^(.+?)(\?.*)?$/)[1] + "?" + encodeURIComponent(jQuery.trim(target.text()));
} }
}); });
li.appendChild( b ); li.appendChild( b );
@ -184,14 +186,14 @@ function expect(asserts) {
* Resets the test setup. Useful for tests that modify the DOM. * Resets the test setup. Useful for tests that modify the DOM.
*/ */
function reset() { function reset() {
$("#main").html( _config.fixture ); jQuery("#main").html( _config.fixture );
$.event.global = {}; jQuery.event.global = {};
$.ajaxSettings = $.extend({}, _config.ajaxSettings); jQuery.ajaxSettings = jQuery.extend({}, _config.ajaxSettings);
} }
/** /**
* Asserts true. * Asserts true.
* @example ok( $("a").size() > 5, "There must be at least 5 anchors" ); * @example ok( jQuery("a").size() > 5, "There must be at least 5 anchors" );
*/ */
function ok(a, msg) { function ok(a, msg) {
_config.Test.push( [ !!a, msg ] ); _config.Test.push( [ !!a, msg ] );

View file

@ -5,7 +5,12 @@
<title>jQuery Test Suite</title> <title>jQuery Test Suite</title>
<link rel="Stylesheet" media="screen" href="data/testsuite.css" /> <link rel="Stylesheet" media="screen" href="data/testsuite.css" />
<!-- Includes --> <!-- Includes -->
<script type="text/javascript">var jQuery = "jQuery", $ = "$"; // For testing .noConflict()</script> <script type="text/javascript">
var jQuery = this.jQuery || "jQuery", // For testing .noConflict()
$ = this.$ || "$",
originaljQuery = jQuery,
original$ = $;
</script>
<script type="text/javascript" src="../dist/jquery.js"></script> <script type="text/javascript" src="../dist/jquery.js"></script>
<script type="text/javascript" src="data/testrunner.js"></script> <script type="text/javascript" src="data/testrunner.js"></script>
<script type="text/javascript" src="unit/core.js"></script> <script type="text/javascript" src="unit/core.js"></script>

11
test/otherlibs/jquery/1.2.1/jquery.js vendored Normal file

File diff suppressed because one or more lines are too long

11
test/otherlibs/jquery/1.2.3/jquery.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -7,15 +7,15 @@ module("ajax");
if ( !isLocal ) { if ( !isLocal ) {
test("$.ajax() - success callbacks", function() { test("jQuery.ajax() - success callbacks", function() {
expect( 8 ); expect( 8 );
$.ajaxSetup({ timeout: 0 }); jQuery.ajaxSetup({ timeout: 0 });
stop(); stop();
setTimeout(function(){ setTimeout(function(){
$('#foo').ajaxStart(function(){ jQuery('#foo').ajaxStart(function(){
ok( true, "ajaxStart" ); ok( true, "ajaxStart" );
}).ajaxStop(function(){ }).ajaxStop(function(){
ok( true, "ajaxStop" ); ok( true, "ajaxStop" );
@ -30,7 +30,7 @@ test("$.ajax() - success callbacks", function() {
ok( true, "ajaxSuccess" ); ok( true, "ajaxSuccess" );
}); });
$.ajax({ jQuery.ajax({
url: url("data/name.html"), url: url("data/name.html"),
beforeSend: function(){ ok(true, "beforeSend"); }, beforeSend: function(){ ok(true, "beforeSend"); },
success: function(){ ok(true, "success"); }, success: function(){ ok(true, "success"); },
@ -40,11 +40,11 @@ test("$.ajax() - success callbacks", function() {
}, 13); }, 13);
}); });
test("$.ajax() - error callbacks", function() { test("jQuery.ajax() - error callbacks", function() {
expect( 8 ); expect( 8 );
stop(); stop();
$('#foo').ajaxStart(function(){ jQuery('#foo').ajaxStart(function(){
ok( true, "ajaxStart" ); ok( true, "ajaxStart" );
}).ajaxStop(function(){ }).ajaxStop(function(){
ok( true, "ajaxStop" ); ok( true, "ajaxStop" );
@ -59,9 +59,9 @@ test("$.ajax() - error callbacks", function() {
ok( false, "ajaxSuccess" ); ok( false, "ajaxSuccess" );
}); });
$.ajaxSetup({ timeout: 500 }); jQuery.ajaxSetup({ timeout: 500 });
$.ajax({ jQuery.ajax({
url: url("data/name.php?wait=5"), url: url("data/name.php?wait=5"),
beforeSend: function(){ ok(true, "beforeSend"); }, beforeSend: function(){ ok(true, "beforeSend"); },
success: function(){ ok(false, "success"); }, success: function(){ ok(false, "success"); },
@ -70,11 +70,11 @@ test("$.ajax() - error callbacks", function() {
}); });
}); });
test("$.ajax() - disabled globals", function() { test("jQuery.ajax() - disabled globals", function() {
expect( 3 ); expect( 3 );
stop(); stop();
$('#foo').ajaxStart(function(){ jQuery('#foo').ajaxStart(function(){
ok( false, "ajaxStart" ); ok( false, "ajaxStart" );
}).ajaxStop(function(){ }).ajaxStop(function(){
ok( false, "ajaxStop" ); ok( false, "ajaxStop" );
@ -88,7 +88,7 @@ test("$.ajax() - disabled globals", function() {
ok( false, "ajaxSuccess" ); ok( false, "ajaxSuccess" );
}); });
$.ajax({ jQuery.ajax({
global: false, global: false,
url: url("data/name.html"), url: url("data/name.html"),
beforeSend: function(){ ok(true, "beforeSend"); }, beforeSend: function(){ ok(true, "beforeSend"); },
@ -101,30 +101,30 @@ test("$.ajax() - disabled globals", function() {
}); });
}); });
test("$.ajax - xml: non-namespace elements inside namespaced elements", function() { test("jQuery.ajax - xml: non-namespace elements inside namespaced elements", function() {
expect(3); expect(3);
stop(); stop();
$.ajax({ jQuery.ajax({
url: url("data/with_fries.xml"), url: url("data/with_fries.xml"),
dataType: "xml", dataType: "xml",
success: function(resp) { success: function(resp) {
equals( $("properties", resp).length, 1, 'properties in responseXML' ); equals( jQuery("properties", resp).length, 1, 'properties in responseXML' );
equals( $("jsconf", resp).length, 1, 'jsconf in responseXML' ); equals( jQuery("jsconf", resp).length, 1, 'jsconf in responseXML' );
equals( $("thing", resp).length, 2, 'things in responseXML' ); equals( jQuery("thing", resp).length, 2, 'things in responseXML' );
start(); start();
} }
}); });
}); });
test("$.ajax - beforeSend", function() { test("jQuery.ajax - beforeSend", function() {
expect(1); expect(1);
stop(); stop();
var check = false; var check = false;
$.ajaxSetup({ timeout: 0 }); jQuery.ajaxSetup({ timeout: 0 });
$.ajax({ jQuery.ajax({
url: url("data/name.html"), url: url("data/name.html"),
beforeSend: function(xml) { beforeSend: function(xml) {
check = true; check = true;
@ -136,9 +136,9 @@ test("$.ajax - beforeSend", function() {
}); });
}); });
test("$.ajax - beforeSend, cancel request (#2688)", function() { test("jQuery.ajax - beforeSend, cancel request (#2688)", function() {
expect(2); expect(2);
var request = $.ajax({ var request = jQuery.ajax({
url: url("data/name.html"), url: url("data/name.html"),
beforeSend: function() { beforeSend: function() {
ok( true, "beforeSend got called, canceling" ); ok( true, "beforeSend got called, canceling" );
@ -159,7 +159,7 @@ test("$.ajax - beforeSend, cancel request (#2688)", function() {
var foobar; var foobar;
test("$.ajax - dataType html", function() { test("jQuery.ajax - dataType html", function() {
expect(5); expect(5);
stop(); stop();
@ -172,11 +172,11 @@ test("$.ajax - dataType html", function() {
start(); start();
}; };
$.ajax({ jQuery.ajax({
dataType: "html", dataType: "html",
url: url("data/test.html"), url: url("data/test.html"),
success: function(data) { success: function(data) {
$("#ap").html(data); jQuery("#ap").html(data);
ok( data.match(/^html text/), 'Check content for datatype html' ); ok( data.match(/^html text/), 'Check content for datatype html' );
setTimeout(verifyEvaluation, 600); setTimeout(verifyEvaluation, 600);
} }
@ -186,55 +186,55 @@ test("$.ajax - dataType html", function() {
test("serialize()", function() { test("serialize()", function() {
expect(6); expect(6);
equals( $('#form').serialize(), equals( jQuery('#form').serialize(),
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2", "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2",
'Check form serialization as query string'); 'Check form serialization as query string');
equals( $('#form :input').serialize(), equals( jQuery('#form :input').serialize(),
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2", "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2",
'Check input serialization as query string'); 'Check input serialization as query string');
equals( $('#testForm').serialize(), equals( jQuery('#testForm').serialize(),
'T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=', 'T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=',
'Check form serialization as query string'); 'Check form serialization as query string');
equals( $('#testForm :input').serialize(), equals( jQuery('#testForm :input').serialize(),
'T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=', 'T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=',
'Check input serialization as query string'); 'Check input serialization as query string');
equals( $('#form, #testForm').serialize(), equals( jQuery('#form, #testForm').serialize(),
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2&T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=", "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2&T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
'Multiple form serialization as query string'); 'Multiple form serialization as query string');
equals( $('#form, #testForm :input').serialize(), equals( jQuery('#form, #testForm :input').serialize(),
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2&T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=", "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2&T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
'Mixed form/input serialization as query string'); 'Mixed form/input serialization as query string');
}); });
test("$.param()", function() { test("jQuery.param()", function() {
expect(4); expect(4);
var params = {foo:"bar", baz:42, quux:"All your base are belong to us"}; var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
equals( $.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" ); equals( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
params = {someName: [1, 2, 3], regularThing: "blah" }; params = {someName: [1, 2, 3], regularThing: "blah" };
equals( $.param(params), "someName=1&someName=2&someName=3&regularThing=blah", "with array" ); equals( jQuery.param(params), "someName=1&someName=2&someName=3&regularThing=blah", "with array" );
params = {"foo[]":["baz", 42, "All your base are belong to us"]}; params = {"foo[]":["baz", 42, "All your base are belong to us"]};
equals( $.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" ); equals( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
params = {"foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us"}; params = {"foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us"};
equals( $.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" ); equals( jQuery.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" );
}); });
test("synchronous request", function() { test("synchronous request", function() {
expect(1); expect(1);
ok( /^{ "data"/.test( $.ajax({url: url("data/json_obj.js"), async: false}).responseText ), "check returned text" ); ok( /^{ "data"/.test( jQuery.ajax({url: url("data/json_obj.js"), async: false}).responseText ), "check returned text" );
}); });
test("synchronous request with callbacks", function() { test("synchronous request with callbacks", function() {
expect(2); expect(2);
var result; var result;
$.ajax({url: url("data/json_obj.js"), async: false, success: function(data) { ok(true, "sucess callback executed"); result = data; } }); jQuery.ajax({url: url("data/json_obj.js"), async: false, success: function(data) { ok(true, "sucess callback executed"); result = data; } });
ok( /^{ "data"/.test( result ), "check returned text" ); ok( /^{ "data"/.test( result ), "check returned text" );
}); });
@ -249,22 +249,22 @@ test("pass-through request object", function() {
var success = function() { var success = function() {
successCount++; successCount++;
}; };
$("#foo").ajaxError(function (e, xml, s, ex) { jQuery("#foo").ajaxError(function (e, xml, s, ex) {
errorCount++; errorCount++;
errorEx += ": " + xml.status; errorEx += ": " + xml.status;
}); });
$("#foo").one('ajaxStop', function () { jQuery("#foo").one('ajaxStop', function () {
equals(successCount, 5, "Check all ajax calls successful"); equals(successCount, 5, "Check all ajax calls successful");
equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")"); equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")");
$("#foo").unbind('ajaxError'); jQuery("#foo").unbind('ajaxError');
start(); start();
}); });
ok( $.get(url(target), success), "get" ); ok( jQuery.get(url(target), success), "get" );
ok( $.post(url(target), success), "post" ); ok( jQuery.post(url(target), success), "post" );
ok( $.getScript(url("data/test.js"), success), "script" ); ok( jQuery.getScript(url("data/test.js"), success), "script" );
ok( $.getJSON(url("data/json_obj.js"), success), "json" ); ok( jQuery.getJSON(url("data/json_obj.js"), success), "json" );
ok( $.ajax({url: url(target), success: success}), "generic" ); ok( jQuery.ajax({url: url(target), success: success}), "generic" );
}); });
test("ajax cache", function () { test("ajax cache", function () {
@ -273,7 +273,7 @@ test("ajax cache", function () {
var count = 0; var count = 0;
$("#firstp").bind("ajaxSuccess", function (e, xml, s) { jQuery("#firstp").bind("ajaxSuccess", function (e, xml, s) {
var re = /_=(.*?)(&|$)/g; var re = /_=(.*?)(&|$)/g;
var oldOne = null; var oldOne = null;
for (var i = 0; i < 6; i++) { for (var i = 0; i < 6; i++) {
@ -289,12 +289,12 @@ test("ajax cache", function () {
start(); start();
}); });
ok( $.ajax({url: "data/text.php", cache:false}), "test with no parameters" ); ok( jQuery.ajax({url: "data/text.php", cache:false}), "test with no parameters" );
ok( $.ajax({url: "data/text.php?pizza=true", cache:false}), "test with 1 parameter" ); ok( jQuery.ajax({url: "data/text.php?pizza=true", cache:false}), "test with 1 parameter" );
ok( $.ajax({url: "data/text.php?_=tobereplaced555", cache:false}), "test with _= parameter" ); ok( jQuery.ajax({url: "data/text.php?_=tobereplaced555", cache:false}), "test with _= parameter" );
ok( $.ajax({url: "data/text.php?pizza=true&_=tobereplaced555", cache:false}), "test with 1 parameter plus _= one" ); ok( jQuery.ajax({url: "data/text.php?pizza=true&_=tobereplaced555", cache:false}), "test with 1 parameter plus _= one" );
ok( $.ajax({url: "data/text.php?_=tobereplaced555&tv=false", cache:false}), "test with 1 parameter plus _= one before it" ); ok( jQuery.ajax({url: "data/text.php?_=tobereplaced555&tv=false", cache:false}), "test with 1 parameter plus _= one before it" );
ok( $.ajax({url: "data/text.php?name=David&_=tobereplaced555&washere=true", cache:false}), "test with 2 parameters surrounding _= one" ); ok( jQuery.ajax({url: "data/text.php?name=David&_=tobereplaced555&washere=true", cache:false}), "test with 2 parameters surrounding _= one" );
}); });
test("global ajaxSettings", function() { test("global ajaxSettings", function() {
@ -304,16 +304,16 @@ test("global ajaxSettings", function() {
var orig = { url: "data/with_fries.xml" }; var orig = { url: "data/with_fries.xml" };
var t; var t;
$.ajaxSetup({ data: {foo: 'bar', bar: 'BAR'} }); jQuery.ajaxSetup({ data: {foo: 'bar', bar: 'BAR'} });
t = jQuery.extend({}, orig); t = jQuery.extend({}, orig);
t.data = {}; t.data = {};
$.ajax(t); jQuery.ajax(t);
ok( t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending {}" ); ok( t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending {}" );
t = jQuery.extend({}, orig); t = jQuery.extend({}, orig);
t.data = { zoo: 'a', ping: 'b' }; t.data = { zoo: 'a', ping: 'b' };
$.ajax(t); jQuery.ajax(t);
ok( t.url.indexOf('ping') > -1 && t.url.indexOf('zoo') > -1 && t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending { zoo: 'a', ping: 'b' }" ); ok( t.url.indexOf('ping') > -1 && t.url.indexOf('zoo') > -1 && t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending { zoo: 'a', ping: 'b' }" );
jQuery.ajaxSettings = tmp; jQuery.ajaxSettings = tmp;
@ -322,14 +322,14 @@ test("global ajaxSettings", function() {
test("load(String)", function() { test("load(String)", function() {
expect(1); expect(1);
stop(true); // check if load can be called with only url stop(true); // check if load can be called with only url
$('#first').load("data/name.html", start); jQuery('#first').load("data/name.html", start);
}); });
test("load('url selector')", function() { test("load('url selector')", function() {
expect(1); expect(1);
stop(true); // check if load can be called with only url stop(true); // check if load can be called with only url
$('#first').load("data/test3.html div.user", function(){ jQuery('#first').load("data/test3.html div.user", function(){
equals( $(this).children("div").length, 2, "Verify that specific elements were injected" ); equals( jQuery(this).children("div").length, 2, "Verify that specific elements were injected" );
start(); start();
}); });
}); });
@ -337,21 +337,21 @@ test("load('url selector')", function() {
test("load(String, Function) with ajaxSetup on dataType json, see #2046", function() { test("load(String, Function) with ajaxSetup on dataType json, see #2046", function() {
expect(1); expect(1);
stop(); stop();
$.ajaxSetup({ dataType: "json" }); jQuery.ajaxSetup({ dataType: "json" });
$("#first").ajaxComplete(function (e, xml, s) { jQuery("#first").ajaxComplete(function (e, xml, s) {
equals( s.dataType, "html", "Verify the load() dataType was html" ); equals( s.dataType, "html", "Verify the load() dataType was html" );
$("#first").unbind("ajaxComplete"); jQuery("#first").unbind("ajaxComplete");
$.ajaxSetup({ dataType: "" }); jQuery.ajaxSetup({ dataType: "" });
start(); start();
}); });
$('#first').load("data/test3.html"); jQuery('#first').load("data/test3.html");
}); });
test("load(String, Function) - simple: inject text into DOM", function() { test("load(String, Function) - simple: inject text into DOM", function() {
expect(2); expect(2);
stop(); stop();
$('#first').load(url("data/name.html"), function() { jQuery('#first').load(url("data/name.html"), function() {
ok( /^ERROR/.test($('#first').text()), 'Check if content was injected into the DOM' ); ok( /^ERROR/.test(jQuery('#first').text()), 'Check if content was injected into the DOM' );
start(); start();
}); });
}); });
@ -363,12 +363,12 @@ test("load(String, Function) - check scripts", function() {
window.foobar = null; window.foobar = null;
var verifyEvaluation = function() { var verifyEvaluation = function() {
equals( foobar, "bar", 'Check if script src was evaluated after load' ); equals( foobar, "bar", 'Check if script src was evaluated after load' );
equals( $('#ap').html(), 'bar', 'Check if script evaluation has modified DOM'); equals( jQuery('#ap').html(), 'bar', 'Check if script evaluation has modified DOM');
start(); start();
}; };
$('#first').load(url('data/test.html'), function() { jQuery('#first').load(url('data/test.html'), function() {
ok( $('#first').html().match(/^html text/), 'Check content after loading html' ); ok( jQuery('#first').html().match(/^html text/), 'Check content after loading html' );
equals( $('#foo').html(), 'foo', 'Check if script evaluation has modified DOM'); equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
equals( testFoo, "foo", 'Check if script was evaluated after load' ); equals( testFoo, "foo", 'Check if script was evaluated after load' );
setTimeout(verifyEvaluation, 600); setTimeout(verifyEvaluation, 600);
}); });
@ -378,8 +378,8 @@ test("load(String, Function) - check file with only a script tag", function() {
expect(3); expect(3);
stop(); stop();
testFoo = undefined; testFoo = undefined;
$('#first').load(url('data/test2.html'), function() { jQuery('#first').load(url('data/test2.html'), function() {
equals( $('#foo').html(), 'foo', 'Check if script evaluation has modified DOM'); equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
equals( testFoo, "foo", 'Check if script was evaluated after load' ); equals( testFoo, "foo", 'Check if script was evaluated after load' );
start(); start();
}); });
@ -389,8 +389,8 @@ test("load(String, Object, Function)", function() {
expect(2); expect(2);
stop(); stop();
$('<div />').load(url('data/params_html.php'), { foo:3, bar:'ok' }, function() { jQuery('<div />').load(url('data/params_html.php'), { foo:3, bar:'ok' }, function() {
var $post = $(this).find('#post'); var $post = jQuery(this).find('#post');
equals( $post.find('#foo').text(), '3', 'Check if a hash of data is passed correctly'); equals( $post.find('#foo').text(), '3', 'Check if a hash of data is passed correctly');
equals( $post.find('#bar').text(), 'ok', 'Check if a hash of data is passed correctly'); equals( $post.find('#bar').text(), 'ok', 'Check if a hash of data is passed correctly');
start(); start();
@ -401,21 +401,21 @@ test("load(String, String, Function)", function() {
expect(2); expect(2);
stop(); stop();
$('<div />').load(url('data/params_html.php'), 'foo=3&bar=ok', function() { jQuery('<div />').load(url('data/params_html.php'), 'foo=3&bar=ok', function() {
var $get = $(this).find('#get'); var $get = jQuery(this).find('#get');
equals( $get.find('#foo').text(), '3', 'Check if a string of data is passed correctly'); equals( $get.find('#foo').text(), '3', 'Check if a string of data is passed correctly');
equals( $get.find('#bar').text(), 'ok', 'Check if a of data is passed correctly'); equals( $get.find('#bar').text(), 'ok', 'Check if a of data is passed correctly');
start(); start();
}); });
}); });
test("$.get(String, Hash, Function) - parse xml and use text() on nodes", function() { test("jQuery.get(String, Hash, Function) - parse xml and use text() on nodes", function() {
expect(2); expect(2);
stop(); stop();
$.get(url('data/dashboard.xml'), function(xml) { jQuery.get(url('data/dashboard.xml'), function(xml) {
var content = []; var content = [];
$('tab', xml).each(function() { jQuery('tab', xml).each(function() {
content.push($(this).text()); content.push(jQuery(this).text());
}); });
equals( content[0], 'blabla', 'Check first tab'); equals( content[0], 'blabla', 'Check first tab');
equals( content[1], 'blublu', 'Check second tab'); equals( content[1], 'blublu', 'Check second tab');
@ -423,23 +423,23 @@ test("$.get(String, Hash, Function) - parse xml and use text() on nodes", functi
}); });
}); });
test("$.getScript(String, Function) - with callback", function() { test("jQuery.getScript(String, Function) - with callback", function() {
expect(2); expect(2);
stop(); stop();
window.foobar = null; window.foobar = null;
$.getScript(url("data/test.js"), function() { jQuery.getScript(url("data/test.js"), function() {
equals( foobar, "bar", 'Check if script was evaluated' ); equals( foobar, "bar", 'Check if script was evaluated' );
setTimeout(start, 100); setTimeout(start, 100);
}); });
}); });
test("$.getScript(String, Function) - no callback", function() { test("jQuery.getScript(String, Function) - no callback", function() {
expect(1); expect(1);
stop(true); stop(true);
$.getScript(url("data/test.js"), start); jQuery.getScript(url("data/test.js"), start);
}); });
test("$.ajax() - JSONP, Local", function() { test("jQuery.ajax() - JSONP, Local", function() {
expect(7); expect(7);
var count = 0; var count = 0;
@ -447,7 +447,7 @@ test("$.ajax() - JSONP, Local", function() {
stop(); stop();
$.ajax({ jQuery.ajax({
url: "data/jsonp.php", url: "data/jsonp.php",
dataType: "jsonp", dataType: "jsonp",
success: function(data){ success: function(data){
@ -460,7 +460,7 @@ test("$.ajax() - JSONP, Local", function() {
} }
}); });
$.ajax({ jQuery.ajax({
url: "data/jsonp.php?callback=?", url: "data/jsonp.php?callback=?",
dataType: "jsonp", dataType: "jsonp",
success: function(data){ success: function(data){
@ -473,7 +473,7 @@ test("$.ajax() - JSONP, Local", function() {
} }
}); });
$.ajax({ jQuery.ajax({
url: "data/jsonp.php", url: "data/jsonp.php",
dataType: "jsonp", dataType: "jsonp",
data: "callback=?", data: "callback=?",
@ -487,7 +487,7 @@ test("$.ajax() - JSONP, Local", function() {
} }
}); });
$.ajax({ jQuery.ajax({
url: "data/jsonp.php", url: "data/jsonp.php",
dataType: "jsonp", dataType: "jsonp",
jsonp: "callback", jsonp: "callback",
@ -501,7 +501,7 @@ test("$.ajax() - JSONP, Local", function() {
} }
}); });
$.ajax({ jQuery.ajax({
type: "POST", type: "POST",
url: "data/jsonp.php", url: "data/jsonp.php",
dataType: "jsonp", dataType: "jsonp",
@ -515,7 +515,7 @@ test("$.ajax() - JSONP, Local", function() {
} }
}); });
$.ajax({ jQuery.ajax({
type: "POST", type: "POST",
url: "data/jsonp.php", url: "data/jsonp.php",
data: "callback=?", data: "callback=?",
@ -530,7 +530,7 @@ test("$.ajax() - JSONP, Local", function() {
} }
}); });
$.ajax({ jQuery.ajax({
type: "POST", type: "POST",
url: "data/jsonp.php", url: "data/jsonp.php",
jsonp: "callback", jsonp: "callback",
@ -546,7 +546,7 @@ test("$.ajax() - JSONP, Local", function() {
}); });
}); });
test("$.ajax() - JSONP, Remote", function() { test("jQuery.ajax() - JSONP, Remote", function() {
expect(4); expect(4);
var count = 0; var count = 0;
@ -556,7 +556,7 @@ test("$.ajax() - JSONP, Remote", function() {
stop(); stop();
$.ajax({ jQuery.ajax({
url: base + "data/jsonp.php", url: base + "data/jsonp.php",
dataType: "jsonp", dataType: "jsonp",
success: function(data){ success: function(data){
@ -569,7 +569,7 @@ test("$.ajax() - JSONP, Remote", function() {
} }
}); });
$.ajax({ jQuery.ajax({
url: base + "data/jsonp.php?callback=?", url: base + "data/jsonp.php?callback=?",
dataType: "jsonp", dataType: "jsonp",
success: function(data){ success: function(data){
@ -582,7 +582,7 @@ test("$.ajax() - JSONP, Remote", function() {
} }
}); });
$.ajax({ jQuery.ajax({
url: base + "data/jsonp.php", url: base + "data/jsonp.php",
dataType: "jsonp", dataType: "jsonp",
data: "callback=?", data: "callback=?",
@ -596,7 +596,7 @@ test("$.ajax() - JSONP, Remote", function() {
} }
}); });
$.ajax({ jQuery.ajax({
url: base + "data/jsonp.php", url: base + "data/jsonp.php",
dataType: "jsonp", dataType: "jsonp",
jsonp: "callback", jsonp: "callback",
@ -611,7 +611,7 @@ test("$.ajax() - JSONP, Remote", function() {
}); });
}); });
test("$.ajax() - script, Remote", function() { test("jQuery.ajax() - script, Remote", function() {
expect(2); expect(2);
var base = window.location.href.replace(/\?.*$/, ""); var base = window.location.href.replace(/\?.*$/, "");
@ -619,7 +619,7 @@ test("$.ajax() - script, Remote", function() {
stop(); stop();
window.foobar = null; window.foobar = null;
$.ajax({ jQuery.ajax({
url: base + "data/test.js", url: base + "data/test.js",
dataType: "script", dataType: "script",
success: function(data){ success: function(data){
@ -629,7 +629,7 @@ test("$.ajax() - script, Remote", function() {
}); });
}); });
test("$.ajax() - script, Remote with POST", function() { test("jQuery.ajax() - script, Remote with POST", function() {
expect(3); expect(3);
var base = window.location.href.replace(/\?.*$/, ""); var base = window.location.href.replace(/\?.*$/, "");
@ -637,7 +637,7 @@ test("$.ajax() - script, Remote with POST", function() {
stop(); stop();
window.foobar = null; window.foobar = null;
$.ajax({ jQuery.ajax({
url: base + "data/test.js", url: base + "data/test.js",
type: "POST", type: "POST",
dataType: "script", dataType: "script",
@ -649,7 +649,7 @@ test("$.ajax() - script, Remote with POST", function() {
}); });
}); });
test("$.ajax() - script, Remote with scheme-less URL", function() { test("jQuery.ajax() - script, Remote with scheme-less URL", function() {
expect(2); expect(2);
var base = window.location.href.replace(/\?.*$/, ""); var base = window.location.href.replace(/\?.*$/, "");
@ -658,7 +658,7 @@ test("$.ajax() - script, Remote with scheme-less URL", function() {
stop(); stop();
window.foobar = null; window.foobar = null;
$.ajax({ jQuery.ajax({
url: base + "data/test.js", url: base + "data/test.js",
dataType: "script", dataType: "script",
success: function(data){ success: function(data){
@ -668,10 +668,10 @@ test("$.ajax() - script, Remote with scheme-less URL", function() {
}); });
}); });
test("$.getJSON(String, Hash, Function) - JSON array", function() { test("jQuery.getJSON(String, Hash, Function) - JSON array", function() {
expect(4); expect(4);
stop(); stop();
$.getJSON(url("data/json.php"), {json: "array"}, function(json) { jQuery.getJSON(url("data/json.php"), {json: "array"}, function(json) {
equals( json[0].name, 'John', 'Check JSON: first, name' ); equals( json[0].name, 'John', 'Check JSON: first, name' );
equals( json[0].age, 21, 'Check JSON: first, age' ); equals( json[0].age, 21, 'Check JSON: first, age' );
equals( json[1].name, 'Peter', 'Check JSON: second, name' ); equals( json[1].name, 'Peter', 'Check JSON: second, name' );
@ -680,60 +680,60 @@ test("$.getJSON(String, Hash, Function) - JSON array", function() {
}); });
}); });
test("$.getJSON(String, Function) - JSON object", function() { test("jQuery.getJSON(String, Function) - JSON object", function() {
expect(2); expect(2);
stop(); stop();
$.getJSON(url("data/json.php"), function(json) { jQuery.getJSON(url("data/json.php"), function(json) {
equals( json.data.lang, 'en', 'Check JSON: lang' ); equals( json.data.lang, 'en', 'Check JSON: lang' );
equals( json.data.length, 25, 'Check JSON: length' ); equals( json.data.length, 25, 'Check JSON: length' );
start(); start();
}); });
}); });
test("$.getJSON(String, Function) - JSON object with absolute url to local content", function() { test("jQuery.getJSON(String, Function) - JSON object with absolute url to local content", function() {
expect(2); expect(2);
var base = window.location.href.replace(/\?.*$/, ""); var base = window.location.href.replace(/\?.*$/, "");
stop(); stop();
$.getJSON(url(base + "data/json.php"), function(json) { jQuery.getJSON(url(base + "data/json.php"), function(json) {
equals( json.data.lang, 'en', 'Check JSON: lang' ); equals( json.data.lang, 'en', 'Check JSON: lang' );
equals( json.data.length, 25, 'Check JSON: length' ); equals( json.data.length, 25, 'Check JSON: length' );
start(); start();
}); });
}); });
test("$.post(String, Hash, Function) - simple with xml", function() { test("jQuery.post(String, Hash, Function) - simple with xml", function() {
expect(4); expect(4);
stop(); stop();
$.post(url("data/name.php"), {xml: "5-2"}, function(xml){ jQuery.post(url("data/name.php"), {xml: "5-2"}, function(xml){
$('math', xml).each(function() { jQuery('math', xml).each(function() {
equals( $('calculation', this).text(), '5-2', 'Check for XML' ); equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
equals( $('result', this).text(), '3', 'Check for XML' ); equals( jQuery('result', this).text(), '3', 'Check for XML' );
}); });
}); });
$.post(url("data/name.php?xml=5-2"), {}, function(xml){ jQuery.post(url("data/name.php?xml=5-2"), {}, function(xml){
$('math', xml).each(function() { jQuery('math', xml).each(function() {
equals( $('calculation', this).text(), '5-2', 'Check for XML' ); equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
equals( $('result', this).text(), '3', 'Check for XML' ); equals( jQuery('result', this).text(), '3', 'Check for XML' );
}); });
start(); start();
}); });
}); });
test("$.ajaxSetup({timeout: Number}) - with global timeout", function() { test("jQuery.ajaxSetup({timeout: Number}) - with global timeout", function() {
stop(); stop();
var passed = 0; var passed = 0;
$.ajaxSetup({timeout: 1000}); jQuery.ajaxSetup({timeout: 1000});
var pass = function() { var pass = function() {
passed++; passed++;
if ( passed == 2 ) { if ( passed == 2 ) {
ok( true, 'Check local and global callbacks after timeout' ); ok( true, 'Check local and global callbacks after timeout' );
$('#main').unbind("ajaxError"); jQuery('#main').unbind("ajaxError");
start(); start();
} }
}; };
@ -743,9 +743,9 @@ test("$.ajaxSetup({timeout: Number}) - with global timeout", function() {
start(); start();
}; };
$('#main').ajaxError(pass); jQuery('#main').ajaxError(pass);
$.ajax({ jQuery.ajax({
type: "GET", type: "GET",
url: url("data/name.php?wait=5"), url: url("data/name.php?wait=5"),
error: pass, error: pass,
@ -753,14 +753,14 @@ test("$.ajaxSetup({timeout: Number}) - with global timeout", function() {
}); });
// reset timeout // reset timeout
$.ajaxSetup({timeout: 0}); jQuery.ajaxSetup({timeout: 0});
}); });
test("$.ajaxSetup({timeout: Number}) with localtimeout", function() { test("jQuery.ajaxSetup({timeout: Number}) with localtimeout", function() {
stop(); stop();
$.ajaxSetup({timeout: 50}); jQuery.ajaxSetup({timeout: 50});
$.ajax({ jQuery.ajax({
type: "GET", type: "GET",
timeout: 5000, timeout: 5000,
url: url("data/name.php?wait=1"), url: url("data/name.php?wait=1"),
@ -775,13 +775,13 @@ test("$.ajaxSetup({timeout: Number}) with localtimeout", function() {
}); });
// reset timeout // reset timeout
$.ajaxSetup({timeout: 0}); jQuery.ajaxSetup({timeout: 0});
}); });
test("$.ajax - simple get", function() { test("jQuery.ajax - simple get", function() {
expect(1); expect(1);
stop(); stop();
$.ajax({ jQuery.ajax({
type: "GET", type: "GET",
url: url("data/name.php?name=foo"), url: url("data/name.php?name=foo"),
success: function(msg){ success: function(msg){
@ -791,10 +791,10 @@ test("$.ajax - simple get", function() {
}); });
}); });
test("$.ajax - simple post", function() { test("jQuery.ajax - simple post", function() {
expect(1); expect(1);
stop(); stop();
$.ajax({ jQuery.ajax({
type: "POST", type: "POST",
url: url("data/name.php"), url: url("data/name.php"),
data: "name=peter", data: "name=peter",
@ -808,19 +808,19 @@ test("$.ajax - simple post", function() {
test("ajaxSetup()", function() { test("ajaxSetup()", function() {
expect(1); expect(1);
stop(); stop();
$.ajaxSetup({ jQuery.ajaxSetup({
url: url("data/name.php?name=foo"), url: url("data/name.php?name=foo"),
success: function(msg){ success: function(msg){
equals( msg, 'bar', 'Check for GET' ); equals( msg, 'bar', 'Check for GET' );
start(); start();
} }
}); });
$.ajax(); jQuery.ajax();
}); });
test("custom timeout does not set error message when timeout occurs, see #970", function() { test("custom timeout does not set error message when timeout occurs, see #970", function() {
stop(); stop();
$.ajax({ jQuery.ajax({
url: "data/name.php?wait=10", url: "data/name.php?wait=10",
timeout: 500, timeout: 500,
error: function(request, status) { error: function(request, status) {
@ -833,7 +833,7 @@ test("custom timeout does not set error message when timeout occurs, see #970",
test("data option: evaluate function values (#2806)", function() { test("data option: evaluate function values (#2806)", function() {
stop(); stop();
$.ajax({ jQuery.ajax({
url: "data/echoQuery.php", url: "data/echoQuery.php",
data: { data: {
key: function() { key: function() {

File diff suppressed because it is too large Load diff

View file

@ -3,7 +3,7 @@ module("dimensions");
test("innerWidth()", function() { test("innerWidth()", function() {
expect(3); expect(3);
var $div = $("#nothiddendiv"); var $div = jQuery("#nothiddendiv");
// set styles // set styles
$div.css({ $div.css({
margin: 10, margin: 10,
@ -24,7 +24,7 @@ test("innerWidth()", function() {
test("innerHeight()", function() { test("innerHeight()", function() {
expect(3); expect(3);
var $div = $("#nothiddendiv"); var $div = jQuery("#nothiddendiv");
// set styles // set styles
$div.css({ $div.css({
margin: 10, margin: 10,
@ -45,7 +45,7 @@ test("innerHeight()", function() {
test("outerWidth()", function() { test("outerWidth()", function() {
expect(6); expect(6);
var $div = $("#nothiddendiv"); var $div = jQuery("#nothiddendiv");
$div.css("width", 30); $div.css("width", 30);
equals($div.outerWidth(), 30, "Test with only width set"); equals($div.outerWidth(), 30, "Test with only width set");
@ -67,7 +67,7 @@ test("outerWidth()", function() {
test("outerHeight()", function() { test("outerHeight()", function() {
expect(6); expect(6);
var $div = $("#nothiddendiv"); var $div = jQuery("#nothiddendiv");
$div.css("height", 30); $div.css("height", 30);
equals($div.outerHeight(), 30, "Test with only width set"); equals($div.outerHeight(), 30, "Test with only width set");

View file

@ -6,9 +6,9 @@ test("bind(), with data", function() {
ok( event.data, "bind() with data, check passed data exists" ); ok( event.data, "bind() with data, check passed data exists" );
equals( event.data.foo, "bar", "bind() with data, Check value of passed data" ); equals( event.data.foo, "bar", "bind() with data, Check value of passed data" );
}; };
$("#firstp").bind("click", {foo: "bar"}, handler).click().unbind("click", handler); jQuery("#firstp").bind("click", {foo: "bar"}, handler).click().unbind("click", handler);
ok( !jQuery.data($("#firstp")[0], "events"), "Event handler unbound when using data." ); ok( !jQuery.data(jQuery("#firstp")[0], "events"), "Event handler unbound when using data." );
}); });
test("bind(), with data, trigger with data", function() { test("bind(), with data, trigger with data", function() {
@ -19,7 +19,7 @@ test("bind(), with data, trigger with data", function() {
ok( data, "Check trigger data" ); ok( data, "Check trigger data" );
equals( data.bar, "foo", "Check value of trigger data" ); equals( data.bar, "foo", "Check value of trigger data" );
}; };
$("#firstp").bind("click", {foo: "bar"}, handler).trigger("click", [{bar: "foo"}]).unbind("click", handler); jQuery("#firstp").bind("click", {foo: "bar"}, handler).trigger("click", [{bar: "foo"}]).unbind("click", handler);
}); });
test("bind(), multiple events at once", function() { test("bind(), multiple events at once", function() {
@ -32,7 +32,7 @@ test("bind(), multiple events at once", function() {
else if (event.type == "mouseover") else if (event.type == "mouseover")
mouseoverCounter += 1; mouseoverCounter += 1;
}; };
$("#firstp").bind("click mouseover", handler).trigger("click").trigger("mouseover"); jQuery("#firstp").bind("click mouseover", handler).trigger("click").trigger("mouseover");
equals( clickCounter, 1, "bind() with multiple events at once" ); equals( clickCounter, 1, "bind() with multiple events at once" );
equals( mouseoverCounter, 1, "bind() with multiple events at once" ); equals( mouseoverCounter, 1, "bind() with multiple events at once" );
}); });
@ -42,7 +42,7 @@ test("bind(), no data", function() {
var handler = function(event) { var handler = function(event) {
ok ( !event.data, "Check that no data is added to the event object" ); ok ( !event.data, "Check that no data is added to the event object" );
}; };
$("#firstp").bind("click", handler).trigger("click"); jQuery("#firstp").bind("click", handler).trigger("click");
}); });
test("bind(), iframes", function() { test("bind(), iframes", function() {
@ -53,7 +53,7 @@ test("bind(), iframes", function() {
// //
// var input = doc.getElementsByTagName("input")[0]; // var input = doc.getElementsByTagName("input")[0];
// //
// $(input).bind("click",function() { // jQuery(input).bind("click",function() {
// ok( true, "Binding to element inside iframe" ); // ok( true, "Binding to element inside iframe" );
// }).click(); // }).click();
}); });
@ -64,89 +64,89 @@ test("bind(), trigger change on select", function() {
function selectOnChange(event) { function selectOnChange(event) {
equals( event.data, counter++, "Event.data is not a global event object" ); equals( event.data, counter++, "Event.data is not a global event object" );
}; };
$("#form select").each(function(i){ jQuery("#form select").each(function(i){
$(this).bind('change', i, selectOnChange); jQuery(this).bind('change', i, selectOnChange);
}).trigger('change'); }).trigger('change');
}); });
test("bind(), namespaced events, cloned events", function() { test("bind(), namespaced events, cloned events", function() {
expect(6); expect(6);
$("#firstp").bind("custom.test",function(e){ jQuery("#firstp").bind("custom.test",function(e){
ok(true, "Custom event triggered"); ok(true, "Custom event triggered");
}); });
$("#firstp").bind("click",function(e){ jQuery("#firstp").bind("click",function(e){
ok(true, "Normal click triggered"); ok(true, "Normal click triggered");
}); });
$("#firstp").bind("click.test",function(e){ jQuery("#firstp").bind("click.test",function(e){
ok(true, "Namespaced click triggered"); ok(true, "Namespaced click triggered");
}); });
// Trigger both bound fn (2) // Trigger both bound fn (2)
$("#firstp").trigger("click"); jQuery("#firstp").trigger("click");
// Trigger one bound fn (1) // Trigger one bound fn (1)
$("#firstp").trigger("click.test"); jQuery("#firstp").trigger("click.test");
// Remove only the one fn // Remove only the one fn
$("#firstp").unbind("click.test"); jQuery("#firstp").unbind("click.test");
// Trigger the remaining fn (1) // Trigger the remaining fn (1)
$("#firstp").trigger("click"); jQuery("#firstp").trigger("click");
// Remove the remaining fn // Remove the remaining fn
$("#firstp").unbind(".test"); jQuery("#firstp").unbind(".test");
// Trigger the remaining fn (0) // Trigger the remaining fn (0)
$("#firstp").trigger("custom"); jQuery("#firstp").trigger("custom");
// using contents will get comments regular, text, and comment nodes // using contents will get comments regular, text, and comment nodes
$("#nonnodes").contents().bind("tester", function () { jQuery("#nonnodes").contents().bind("tester", function () {
equals(this.nodeType, 1, "Check node,textnode,comment bind just does real nodes" ); equals(this.nodeType, 1, "Check node,textnode,comment bind just does real nodes" );
}).trigger("tester"); }).trigger("tester");
// Make sure events stick with appendTo'd elements (which are cloned) #2027 // Make sure events stick with appendTo'd elements (which are cloned) #2027
$("<a href='#fail' class='test'>test</a>").click(function(){ return false; }).appendTo("p"); jQuery("<a href='#fail' class='test'>test</a>").click(function(){ return false; }).appendTo("p");
ok( $("a.test:first").triggerHandler("click") === false, "Handler is bound to appendTo'd elements" ); ok( jQuery("a.test:first").triggerHandler("click") === false, "Handler is bound to appendTo'd elements" );
}); });
test("trigger() shortcuts", function() { test("trigger() shortcuts", function() {
expect(6); expect(6);
$('<li><a href="#">Change location</a></li>').prependTo('#firstUL').find('a').bind('click', function() { jQuery('<li><a href="#">Change location</a></li>').prependTo('#firstUL').find('a').bind('click', function() {
var close = $('spanx', this); // same with $(this).find('span'); var close = jQuery('spanx', this); // same with jQuery(this).find('span');
equals( close.length, 0, "Context element does not exist, length must be zero" ); equals( close.length, 0, "Context element does not exist, length must be zero" );
ok( !close[0], "Context element does not exist, direct access to element must return undefined" ); ok( !close[0], "Context element does not exist, direct access to element must return undefined" );
return false; return false;
}).click(); }).click();
$("#check1").click(function() { jQuery("#check1").click(function() {
ok( true, "click event handler for checkbox gets fired twice, see #815" ); ok( true, "click event handler for checkbox gets fired twice, see #815" );
}).click(); }).click();
var counter = 0; var counter = 0;
$('#firstp')[0].onclick = function(event) { jQuery('#firstp')[0].onclick = function(event) {
counter++; counter++;
}; };
$('#firstp').click(); jQuery('#firstp').click();
equals( counter, 1, "Check that click, triggers onclick event handler also" ); equals( counter, 1, "Check that click, triggers onclick event handler also" );
var clickCounter = 0; var clickCounter = 0;
$('#simon1')[0].onclick = function(event) { jQuery('#simon1')[0].onclick = function(event) {
clickCounter++; clickCounter++;
}; };
$('#simon1').click(); jQuery('#simon1').click();
equals( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" ); equals( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" );
$('<img />').load(function(){ jQuery('<img />').load(function(){
ok( true, "Trigger the load event, using the shortcut .load() (#2819)"); ok( true, "Trigger the load event, using the shortcut .load() (#2819)");
}).load(); }).load();
}); });
test("unbind(event)", function() { test("unbind(event)", function() {
expect(8); expect(8);
var el = $("#firstp"); var el = jQuery("#firstp");
el.click(function() { el.click(function() {
ok( true, "Fake normal bind" ); ok( true, "Fake normal bind" );
}); });
@ -176,7 +176,7 @@ test("unbind(event)", function() {
else if (event.type == "mouseover") else if (event.type == "mouseover")
mouseoverCounter += 1; mouseoverCounter += 1;
}; };
$("#firstp").bind("click mouseover", handler).unbind("click mouseover", handler).trigger("click").trigger("mouseover"); jQuery("#firstp").bind("click mouseover", handler).unbind("click mouseover", handler).trigger("click").trigger("mouseover");
equals( clickCounter, 0, "unbind() with multiple events at once" ); equals( clickCounter, 0, "unbind() with multiple events at once" );
equals( mouseoverCounter, 0, "unbind() with multiple events at once" ); equals( mouseoverCounter, 0, "unbind() with multiple events at once" );
}); });
@ -215,50 +215,50 @@ test("trigger(event, [data], [fn])", function() {
}; };
// Simulate a "native" click // Simulate a "native" click
$("#firstp")[0].click = function(){ jQuery("#firstp")[0].click = function(){
ok( true, "Native call was triggered" ); ok( true, "Native call was triggered" );
}; };
// Triggers handlrs and native // Triggers handlrs and native
// Trigger 5 // Trigger 5
$("#firstp").bind("click", handler).trigger("click", [1, "2", "abc"]); jQuery("#firstp").bind("click", handler).trigger("click", [1, "2", "abc"]);
// Triggers handlers, native, and extra fn // Triggers handlers, native, and extra fn
// Triggers 9 // Triggers 9
$("#firstp").trigger("click", [1, "2", "abc"], handler4); jQuery("#firstp").trigger("click", [1, "2", "abc"], handler4);
// Simulate a "native" click // Simulate a "native" click
$("#firstp")[0].click = function(){ jQuery("#firstp")[0].click = function(){
ok( false, "Native call was triggered" ); ok( false, "Native call was triggered" );
}; };
// Triggers handlers, native, and extra fn // Triggers handlers, native, and extra fn
// Triggers 7 // Triggers 7
$("#firstp").trigger("click", [1, "2", "abc"], handler2); jQuery("#firstp").trigger("click", [1, "2", "abc"], handler2);
// Trigger only the handlers (no native) // Trigger only the handlers (no native)
// Triggers 5 // Triggers 5
equals( $("#firstp").triggerHandler("click", [1, "2", "abc"]), "test", "Verify handler response" ); equals( jQuery("#firstp").triggerHandler("click", [1, "2", "abc"]), "test", "Verify handler response" );
// Trigger only the handlers (no native) and extra fn // Trigger only the handlers (no native) and extra fn
// Triggers 8 // Triggers 8
equals( $("#firstp").triggerHandler("click", [1, "2", "abc"], handler2), false, "Verify handler response" ); equals( jQuery("#firstp").triggerHandler("click", [1, "2", "abc"], handler2), false, "Verify handler response" );
// Build fake click event to pass in // Build fake click event to pass in
var eventObj = jQuery.event.fix({ type: "foo", target: document.body }); var eventObj = jQuery.event.fix({ type: "foo", target: document.body });
// Trigger only the handlers (no native), with external event obj // Trigger only the handlers (no native), with external event obj
// Triggers 5 // Triggers 5
equals( $("#firstp").triggerHandler("click", [eventObj, 1, "2", "abc"]), "test", "Verify handler response" ); equals( jQuery("#firstp").triggerHandler("click", [eventObj, 1, "2", "abc"]), "test", "Verify handler response" );
// Trigger only the handlers (no native) and extra fn, with external event obj // Trigger only the handlers (no native) and extra fn, with external event obj
// Triggers 9 // Triggers 9
eventObj = jQuery.event.fix({ type: "foo", target: document.body }); eventObj = jQuery.event.fix({ type: "foo", target: document.body });
equals( $("#firstp").triggerHandler("click", [eventObj, 1, "2", "abc"], handler), "test", "Verify handler response" ); equals( jQuery("#firstp").triggerHandler("click", [eventObj, 1, "2", "abc"], handler), "test", "Verify handler response" );
var pass = true; var pass = true;
try { try {
$('input:first') jQuery('input:first')
.hide() .hide()
.trigger('focus'); .trigger('focus');
} catch(e) { } catch(e) {
@ -268,11 +268,11 @@ test("trigger(event, [data], [fn])", function() {
// have the extra handler override the return // have the extra handler override the return
// Triggers 9 // Triggers 9
equals( $("#firstp").triggerHandler("click", [1, "2", "abc"], handler3), "newVal", "Verify triggerHandler return is overwritten by extra function" ); equals( jQuery("#firstp").triggerHandler("click", [1, "2", "abc"], handler3), "newVal", "Verify triggerHandler return is overwritten by extra function" );
// have the extra handler leave the return value alone // have the extra handler leave the return value alone
// Triggers 9 // Triggers 9
equals( $("#firstp").triggerHandler("click", [1, "2", "abc"], handler4), "test", "Verify triggerHandler return is not overwritten by extra function" ); equals( jQuery("#firstp").triggerHandler("click", [1, "2", "abc"], handler4), "test", "Verify triggerHandler return is not overwritten by extra function" );
}); });
test("toggle(Function, Function, ...)", function() { test("toggle(Function, Function, ...)", function() {
@ -282,18 +282,18 @@ test("toggle(Function, Function, ...)", function() {
fn1 = function(e) { count++; }, fn1 = function(e) { count++; },
fn2 = function(e) { count--; }, fn2 = function(e) { count--; },
preventDefault = function(e) { e.preventDefault() }, preventDefault = function(e) { e.preventDefault() },
link = $('#mark'); link = jQuery('#mark');
link.click(preventDefault).click().toggle(fn1, fn2).click().click().click().click().click(); link.click(preventDefault).click().toggle(fn1, fn2).click().click().click().click().click();
equals( count, 1, "Check for toggle(fn, fn)" ); equals( count, 1, "Check for toggle(fn, fn)" );
$("#firstp").toggle(function () { jQuery("#firstp").toggle(function () {
equals(arguments.length, 4, "toggle correctly passes through additional triggered arguments, see #1701" ) equals(arguments.length, 4, "toggle correctly passes through additional triggered arguments, see #1701" )
}, function() {}).trigger("click", [ 1, 2, 3 ]); }, function() {}).trigger("click", [ 1, 2, 3 ]);
var first = 0; var first = 0;
$("#simon1").one("click", function() { jQuery("#simon1").one("click", function() {
ok( true, "Execute event only once" ); ok( true, "Execute event only once" );
$(this).toggle(function() { jQuery(this).toggle(function() {
equals( first++, 0, "toggle(Function,Function) assigned from within one('xxx'), see #1054" ); equals( first++, 0, "toggle(Function,Function) assigned from within one('xxx'), see #1054" );
}, function() { }, function() {
equals( first, 1, "toggle(Function,Function) assigned from within one('xxx'), see #1054" ); equals( first, 1, "toggle(Function,Function) assigned from within one('xxx'), see #1054" );
@ -314,7 +314,7 @@ test("toggle(Function, Function, ...)", function() {
} }
]; ];
var $div = $("<div>&nbsp;</div>").toggle( fns[0], fns[1], fns[2] ); var $div = jQuery("<div>&nbsp;</div>").toggle( fns[0], fns[1], fns[2] );
$div.click(); $div.click();
equals( turn, 1, "Trying toggle with 3 functions, attempt 1 yields 1"); equals( turn, 1, "Trying toggle with 3 functions, attempt 1 yields 1");
$div.click(); $div.click();
@ -327,7 +327,7 @@ test("toggle(Function, Function, ...)", function() {
equals( turn, 2, "Trying toggle with 3 functions, attempt 5 yields 2"); equals( turn, 2, "Trying toggle with 3 functions, attempt 5 yields 2");
$div.unbind('click',fns[0]); $div.unbind('click',fns[0]);
var data = $.data( $div[0], 'events' ); var data = jQuery.data( $div[0], 'events' );
ok( !data, "Unbinding one function from toggle unbinds them all"); ok( !data, "Unbinding one function from toggle unbinds them all");
}); });
@ -341,7 +341,7 @@ test("jQuery(function($) {})", function() {
test("event properties", function() { test("event properties", function() {
stop(); stop();
$("#simon1").click(function(event) { jQuery("#simon1").click(function(event) {
ok( event.timeStamp, "assert event.timeStamp is present" ); ok( event.timeStamp, "assert event.timeStamp is present" );
start(); start();
}).click(); }).click();

View file

@ -4,8 +4,8 @@ test("animate(Hash, Object, Function)", function() {
expect(1); expect(1);
stop(); stop();
var hash = {opacity: 'show'}; var hash = {opacity: 'show'};
var hashCopy = $.extend({}, hash); var hashCopy = jQuery.extend({}, hash);
$('#foo').animate(hash, 0, function() { jQuery('#foo').animate(hash, 0, function() {
equals( hash.opacity, hashCopy.opacity, 'Check if animate changed the hash parameter' ); equals( hash.opacity, hashCopy.opacity, 'Check if animate changed the hash parameter' );
start(); start();
}); });
@ -17,7 +17,7 @@ test("animate option (queue === false)", function () {
var order = []; var order = [];
var $foo = $("#foo"); var $foo = jQuery("#foo");
$foo.animate({width:'100px'}, 200, function () { $foo.animate({width:'100px'}, 200, function () {
// should finish after unqueued animation so second // should finish after unqueued animation so second
order.push(2); order.push(2);
@ -38,7 +38,7 @@ test("queue() defaults to 'fx' type", function () {
expect(2); expect(2);
stop(); stop();
var $foo = $("#foo"); var $foo = jQuery("#foo");
$foo.queue("fx", [ "sample", "array" ]); $foo.queue("fx", [ "sample", "array" ]);
var arr = $foo.queue(); var arr = $foo.queue();
isSet(arr, [ "sample", "array" ], "queue() got an array set with type 'fx'"); isSet(arr, [ "sample", "array" ], "queue() got an array set with type 'fx'");
@ -55,7 +55,7 @@ test("stop()", function() {
expect(3); expect(3);
stop(); stop();
var $foo = $("#nothiddendiv"); var $foo = jQuery("#nothiddendiv");
var w = 0; var w = 0;
$foo.hide().width(200).width(); $foo.hide().width(200).width();
@ -78,7 +78,7 @@ test("stop() - several in queue", function() {
expect(4); expect(4);
stop(); stop();
var $foo = $("#nothiddendiv"); var $foo = jQuery("#nothiddendiv");
var w = 0; var w = 0;
$foo.hide().width(200).width(); $foo.hide().width(200).width();
@ -103,7 +103,7 @@ test("stop(clearQueue)", function() {
expect(4); expect(4);
stop(); stop();
var $foo = $("#nothiddendiv"); var $foo = jQuery("#nothiddendiv");
var w = 0; var w = 0;
$foo.hide().width(200).width(); $foo.hide().width(200).width();
@ -130,7 +130,7 @@ test("stop(clearQueue, gotoEnd)", function() {
expect(3); expect(3);
stop(); stop();
var $foo = $("#nothiddendiv"); var $foo = jQuery("#nothiddendiv");
var w = 0; var w = 0;
$foo.hide().width(200).width(); $foo.hide().width(200).width();
@ -156,7 +156,7 @@ test("stop(clearQueue, gotoEnd)", function() {
test("toggle()", function() { test("toggle()", function() {
expect(3); expect(3);
var x = $("#foo"); var x = jQuery("#foo");
ok( x.is(":visible"), "is visible" ); ok( x.is(":visible"), "is visible" );
x.toggle(); x.toggle();
ok( x.is(":hidden"), "is hidden" ); ok( x.is(":hidden"), "is hidden" );
@ -167,68 +167,68 @@ test("toggle()", function() {
var visible = { var visible = {
Normal: function(elem){}, Normal: function(elem){},
"CSS Hidden": function(elem){ "CSS Hidden": function(elem){
$(this).addClass("hidden"); jQuery(this).addClass("hidden");
}, },
"JS Hidden": function(elem){ "JS Hidden": function(elem){
$(this).hide(); jQuery(this).hide();
} }
}; };
var from = { var from = {
"CSS Auto": function(elem,prop){ "CSS Auto": function(elem,prop){
$(elem).addClass("auto" + prop) jQuery(elem).addClass("auto" + prop)
.text("This is a long string of text."); .text("This is a long string of text.");
return ""; return "";
}, },
"JS Auto": function(elem,prop){ "JS Auto": function(elem,prop){
$(elem).css(prop,"auto") jQuery(elem).css(prop,"auto")
.text("This is a long string of text."); .text("This is a long string of text.");
return ""; return "";
}, },
"CSS 100": function(elem,prop){ "CSS 100": function(elem,prop){
$(elem).addClass("large" + prop); jQuery(elem).addClass("large" + prop);
return ""; return "";
}, },
"JS 100": function(elem,prop){ "JS 100": function(elem,prop){
$(elem).css(prop,prop == "opacity" ? 1 : "100px"); jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
return prop == "opacity" ? 1 : 100; return prop == "opacity" ? 1 : 100;
}, },
"CSS 50": function(elem,prop){ "CSS 50": function(elem,prop){
$(elem).addClass("med" + prop); jQuery(elem).addClass("med" + prop);
return ""; return "";
}, },
"JS 50": function(elem,prop){ "JS 50": function(elem,prop){
$(elem).css(prop,prop == "opacity" ? 0.50 : "50px"); jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
return prop == "opacity" ? 0.5 : 50; return prop == "opacity" ? 0.5 : 50;
}, },
"CSS 0": function(elem,prop){ "CSS 0": function(elem,prop){
$(elem).addClass("no" + prop); jQuery(elem).addClass("no" + prop);
return ""; return "";
}, },
"JS 0": function(elem,prop){ "JS 0": function(elem,prop){
$(elem).css(prop,prop == "opacity" ? 0 : "0px"); jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
return 0; return 0;
} }
}; };
var to = { var to = {
"show": function(elem,prop){ "show": function(elem,prop){
$(elem).hide().addClass("wide"+prop); jQuery(elem).hide().addClass("wide"+prop);
return "show"; return "show";
}, },
"hide": function(elem,prop){ "hide": function(elem,prop){
$(elem).addClass("wide"+prop); jQuery(elem).addClass("wide"+prop);
return "hide"; return "hide";
}, },
"100": function(elem,prop){ "100": function(elem,prop){
$(elem).addClass("wide"+prop); jQuery(elem).addClass("wide"+prop);
return prop == "opacity" ? 1 : 100; return prop == "opacity" ? 1 : 100;
}, },
"50": function(elem,prop){ "50": function(elem,prop){
return prop == "opacity" ? 0.50 : 50; return prop == "opacity" ? 0.50 : 50;
}, },
"0": function(elem,prop){ "0": function(elem,prop){
$(elem).addClass("noback"); jQuery(elem).addClass("noback");
return 0; return 0;
} }
}; };
@ -339,7 +339,7 @@ jQuery.each( from, function(fn, f){
if ( t_h == "show" ) { if ( t_h == "show" ) {
var old_h = jQuery.curCSS(this, "height"); var old_h = jQuery.curCSS(this, "height");
$(elem).append("<br/>Some more text<br/>and some more..."); jQuery(elem).append("<br/>Some more text<br/>and some more...");
ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto."); ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
} }
@ -374,50 +374,50 @@ function checkState(){
// Chaining Tests // Chaining Tests
test("Chain fadeOut fadeIn", function() { test("Chain fadeOut fadeIn", function() {
$('#fadein div').saveState().fadeOut('fast').fadeIn('fast',checkState); jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',checkState);
}); });
test("Chain fadeIn fadeOut", function() { test("Chain fadeIn fadeOut", function() {
$('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',checkState); jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',checkState);
}); });
test("Chain hide show", function() { test("Chain hide show", function() {
$('#show div').saveState().hide('fast').show('fast',checkState); jQuery('#show div').saveState().hide('fast').show('fast',checkState);
}); });
test("Chain show hide", function() { test("Chain show hide", function() {
$('#hide div').saveState().show('fast').hide('fast',checkState); jQuery('#hide div').saveState().show('fast').hide('fast',checkState);
}); });
test("Chain toggle in", function() { test("Chain toggle in", function() {
$('#togglein div').saveState().toggle('fast').toggle('fast',checkState); jQuery('#togglein div').saveState().toggle('fast').toggle('fast',checkState);
}); });
test("Chain toggle out", function() { test("Chain toggle out", function() {
$('#toggleout div').saveState().toggle('fast').toggle('fast',checkState); jQuery('#toggleout div').saveState().toggle('fast').toggle('fast',checkState);
}); });
test("Chain slideDown slideUp", function() { test("Chain slideDown slideUp", function() {
$('#slidedown div').saveState().slideDown('fast').slideUp('fast',checkState); jQuery('#slidedown div').saveState().slideDown('fast').slideUp('fast',checkState);
}); });
test("Chain slideUp slideDown", function() { test("Chain slideUp slideDown", function() {
$('#slideup div').saveState().slideUp('fast').slideDown('fast',checkState); jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast',checkState);
}); });
test("Chain slideToggle in", function() { test("Chain slideToggle in", function() {
$('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',checkState); jQuery('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',checkState);
}); });
test("Chain slideToggle out", function() { test("Chain slideToggle out", function() {
$('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',checkState); jQuery('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',checkState);
}); });
function makeTest( text ){ function makeTest( text ){
var elem = $("<div></div>") var elem = jQuery("<div></div>")
.attr("id", "test" + makeTest.id++) .attr("id", "test" + makeTest.id++)
.addClass("box"); .addClass("box");
$("<h4></h4>") jQuery("<h4></h4>")
.text( text ) .text( text )
.appendTo("#fx-tests") .appendTo("#fx-tests")
.click(function(){ .click(function(){
$(this).next().toggle(); jQuery(this).next().toggle();
}) })
.after( elem ); .after( elem );

View file

@ -4,7 +4,7 @@ module("offset");
var testwin = function(name, fn) { var testwin = function(name, fn) {
testwin[name] = load_offset_fixture(name); testwin[name] = load_offset_fixture(name);
var interval = setInterval(function() { var interval = setInterval(function() {
if (testwin[name] && testwin[name].$ && testwin[name].$.isReady) { if (testwin[name] && testwin[name].$ && testwin[name].jQuery.isReady) {
clearInterval(interval); clearInterval(interval);
test(name, fn); test(name, fn);
} }
@ -23,30 +23,30 @@ var testwin = function(name, fn) {
testwin("absolute", function() { testwin("absolute", function() {
var $w = testwin["absolute"].$; var $w = testwin["absolute"].$;
equals( $w('#absolute-1').offset().top, 1, "$('#absolute-1').offset().top" ); equals( $w('#absolute-1').offset().top, 1, "jQuery('#absolute-1').offset().top" );
equals( $w('#absolute-1').offset().left, 1, "$('#absolute-1').offset().left" ); equals( $w('#absolute-1').offset().left, 1, "jQuery('#absolute-1').offset().left" );
equals( $w('#absolute-1-1').offset().top, 5, "$('#absolute-1-1').offset().top" ); equals( $w('#absolute-1-1').offset().top, 5, "jQuery('#absolute-1-1').offset().top" );
equals( $w('#absolute-1-1').offset().left, 5, "$('#absolute-1-1').offset().left" ); equals( $w('#absolute-1-1').offset().left, 5, "jQuery('#absolute-1-1').offset().left" );
equals( $w('#absolute-1-1-1').offset().top, 9, "$('#absolute-1-1-1').offset().top" ); equals( $w('#absolute-1-1-1').offset().top, 9, "jQuery('#absolute-1-1-1').offset().top" );
equals( $w('#absolute-1-1-1').offset().left, 9, "$('#absolute-1-1-1').offset().left" ); equals( $w('#absolute-1-1-1').offset().left, 9, "jQuery('#absolute-1-1-1').offset().left" );
equals( $w('#absolute-2').offset().top, 20, "$('#absolute-2').offset().top" ); equals( $w('#absolute-2').offset().top, 20, "jQuery('#absolute-2').offset().top" );
equals( $w('#absolute-2').offset().left, 20, "$('#absolute-2').offset().left" ); equals( $w('#absolute-2').offset().left, 20, "jQuery('#absolute-2').offset().left" );
equals( $w('#absolute-1').position().top, 0, "$('#absolute-1').position().top" ); equals( $w('#absolute-1').position().top, 0, "jQuery('#absolute-1').position().top" );
equals( $w('#absolute-1').position().left, 0, "$('#absolute-1').position().left" ); equals( $w('#absolute-1').position().left, 0, "jQuery('#absolute-1').position().left" );
equals( $w('#absolute-1-1').position().top, 1, "$('#absolute-1-1').position().top" ); equals( $w('#absolute-1-1').position().top, 1, "jQuery('#absolute-1-1').position().top" );
equals( $w('#absolute-1-1').position().left, 1, "$('#absolute-1-1').position().left" ); equals( $w('#absolute-1-1').position().left, 1, "jQuery('#absolute-1-1').position().left" );
equals( $w('#absolute-1-1-1').position().top, 1, "$('#absolute-1-1-1').position().top" ); equals( $w('#absolute-1-1-1').position().top, 1, "jQuery('#absolute-1-1-1').position().top" );
equals( $w('#absolute-1-1-1').position().left, 1, "$('#absolute-1-1-1').position().left" ); equals( $w('#absolute-1-1-1').position().left, 1, "jQuery('#absolute-1-1-1').position().left" );
equals( $w('#absolute-2').position().top, 19, "$('#absolute-2').position().top" ); equals( $w('#absolute-2').position().top, 19, "jQuery('#absolute-2').position().top" );
equals( $w('#absolute-2').position().left, 19, "$('#absolute-2').position().left" ); equals( $w('#absolute-2').position().left, 19, "jQuery('#absolute-2').position().left" );
testwin["absolute"].close(); testwin["absolute"].close();
}); });
@ -55,29 +55,29 @@ testwin("relative", function() {
var $w = testwin["relative"].$; var $w = testwin["relative"].$;
// IE is collapsing the top margin of 1px // IE is collapsing the top margin of 1px
equals( $w('#relative-1').offset().top, $.browser.msie ? 6 : 7, "$('#relative-1').offset().top" ); equals( $w('#relative-1').offset().top, jQuery.browser.msie ? 6 : 7, "jQuery('#relative-1').offset().top" );
equals( $w('#relative-1').offset().left, 7, "$('#relative-1').offset().left" ); equals( $w('#relative-1').offset().left, 7, "jQuery('#relative-1').offset().left" );
// IE is collapsing the top margin of 1px // IE is collapsing the top margin of 1px
equals( $w('#relative-1-1').offset().top, $.browser.msie ? 13 : 15, "$('#relative-1-1').offset().top" ); equals( $w('#relative-1-1').offset().top, jQuery.browser.msie ? 13 : 15, "jQuery('#relative-1-1').offset().top" );
equals( $w('#relative-1-1').offset().left, 15, "$('#relative-1-1').offset().left" ); equals( $w('#relative-1-1').offset().left, 15, "jQuery('#relative-1-1').offset().left" );
// IE is collapsing the top margin of 1px // IE is collapsing the top margin of 1px
equals( $w('#relative-2').offset().top, $.browser.msie ? 141 : 142, "$('#relative-2').offset().top" ); equals( $w('#relative-2').offset().top, jQuery.browser.msie ? 141 : 142, "jQuery('#relative-2').offset().top" );
equals( $w('#relative-2').offset().left, 27, "$('#relative-2').offset().left" ); equals( $w('#relative-2').offset().left, 27, "jQuery('#relative-2').offset().left" );
// IE is collapsing the top margin of 1px // IE is collapsing the top margin of 1px
equals( $w('#relative-1').position().top, $.browser.msie ? 5 : 6, "$('#relative-1').position().top" ); equals( $w('#relative-1').position().top, jQuery.browser.msie ? 5 : 6, "jQuery('#relative-1').position().top" );
equals( $w('#relative-1').position().left, 6, "$('#relative-1').position().left" ); equals( $w('#relative-1').position().left, 6, "jQuery('#relative-1').position().left" );
// IE is collapsing the top margin of 1px // IE is collapsing the top margin of 1px
equals( $w('#relative-1-1').position().top, $.browser.msie ? 4 : 5, "$('#relative-1-1').position().top" ); equals( $w('#relative-1-1').position().top, jQuery.browser.msie ? 4 : 5, "jQuery('#relative-1-1').position().top" );
equals( $w('#relative-1-1').position().left, 5, "$('#relative-1-1').position().left" ); equals( $w('#relative-1-1').position().left, 5, "jQuery('#relative-1-1').position().left" );
// IE is collapsing the top margin of 1px // IE is collapsing the top margin of 1px
equals( $w('#relative-2').position().top, $.browser.msie ? 140 : 141, "$('#relative-2').position().top" ); equals( $w('#relative-2').position().top, jQuery.browser.msie ? 140 : 141, "jQuery('#relative-2').position().top" );
equals( $w('#relative-2').position().left, 26, "$('#relative-2').position().left" ); equals( $w('#relative-2').position().left, 26, "jQuery('#relative-2').position().left" );
testwin["relative"].close(); testwin["relative"].close();
}); });
@ -86,50 +86,50 @@ testwin("static", function() {
var $w = testwin["static"].$; var $w = testwin["static"].$;
// IE is collapsing the top margin of 1px // IE is collapsing the top margin of 1px
equals( $w('#static-1').offset().top, $.browser.msie ? 6 : 7, "$('#static-1').offset().top" ); equals( $w('#static-1').offset().top, jQuery.browser.msie ? 6 : 7, "jQuery('#static-1').offset().top" );
equals( $w('#static-1').offset().left, 7, "$('#static-1').offset().left" ); equals( $w('#static-1').offset().left, 7, "jQuery('#static-1').offset().left" );
// IE is collapsing the top margin of 1px // IE is collapsing the top margin of 1px
equals( $w('#static-1-1').offset().top, $.browser.msie ? 13 : 15, "$('#static-1-1').offset().top" ); equals( $w('#static-1-1').offset().top, jQuery.browser.msie ? 13 : 15, "jQuery('#static-1-1').offset().top" );
equals( $w('#static-1-1').offset().left, 15, "$('#static-1-1').offset().left" ); equals( $w('#static-1-1').offset().left, 15, "jQuery('#static-1-1').offset().left" );
// IE is collapsing the top margin of 1px // IE is collapsing the top margin of 1px
equals( $w('#static-1-1-1').offset().top, $.browser.msie ? 20 : 23, "$('#static-1-1-1').offset().top" ); equals( $w('#static-1-1-1').offset().top, jQuery.browser.msie ? 20 : 23, "jQuery('#static-1-1-1').offset().top" );
equals( $w('#static-1-1-1').offset().left, 23, "$('#static-1-1-1').offset().left" ); equals( $w('#static-1-1-1').offset().left, 23, "jQuery('#static-1-1-1').offset().left" );
// IE is collapsing the top margin of 1px // IE is collapsing the top margin of 1px
equals( $w('#static-2').offset().top, $.browser.msie ? 121 : 122, "$('#static-2').offset().top" ); equals( $w('#static-2').offset().top, jQuery.browser.msie ? 121 : 122, "jQuery('#static-2').offset().top" );
equals( $w('#static-2').offset().left, 7, "$('#static-2').offset().left" ); equals( $w('#static-2').offset().left, 7, "jQuery('#static-2').offset().left" );
// IE is collapsing the top margin of 1px // IE is collapsing the top margin of 1px
equals( $w('#static-1').position().top, $.browser.msie ? 5 : 6, "$('#static-1').position().top" ); equals( $w('#static-1').position().top, jQuery.browser.msie ? 5 : 6, "jQuery('#static-1').position().top" );
equals( $w('#static-1').position().left, 6, "$('#static-1').position().left" ); equals( $w('#static-1').position().left, 6, "jQuery('#static-1').position().left" );
// IE is collapsing the top margin of 1px // IE is collapsing the top margin of 1px
equals( $w('#static-1-1').position().top, $.browser.msie ? 12 : 14, "$('#static-1-1').position().top" ); equals( $w('#static-1-1').position().top, jQuery.browser.msie ? 12 : 14, "jQuery('#static-1-1').position().top" );
equals( $w('#static-1-1').position().left, 14, "$('#static-1-1').position().left" ); equals( $w('#static-1-1').position().left, 14, "jQuery('#static-1-1').position().left" );
// IE is collapsing the top margin of 1px // IE is collapsing the top margin of 1px
equals( $w('#static-1-1-1').position().top, $.browser.msie ? 19 : 22, "$('#static-1-1-1').position().top" ); equals( $w('#static-1-1-1').position().top, jQuery.browser.msie ? 19 : 22, "jQuery('#static-1-1-1').position().top" );
equals( $w('#static-1-1-1').position().left, 22, "$('#static-1-1-1').position().left" ); equals( $w('#static-1-1-1').position().left, 22, "jQuery('#static-1-1-1').position().left" );
// IE is collapsing the top margin of 1px // IE is collapsing the top margin of 1px
equals( $w('#static-2').position().top, $.browser.msie ? 120 : 121, "$('#static-2').position().top" ); equals( $w('#static-2').position().top, jQuery.browser.msie ? 120 : 121, "jQuery('#static-2').position().top" );
equals( $w('#static-2').position().left, 6, "$('#static-2').position().left" ); equals( $w('#static-2').position().left, 6, "jQuery('#static-2').position().left" );
testwin["static"].close(); testwin["static"].close();
}); });
if ( !$.browser.msie || ($.browser.msie && parseInt($.browser.version) > 6) ) if ( !jQuery.browser.msie || (jQuery.browser.msie && parseInt(jQuery.browser.version) > 6) )
testwin("fixed", function() { testwin("fixed", function() {
var $w = testwin["fixed"].$; var $w = testwin["fixed"].$;
equals( $w('#fixed-1').offset().top, 1001, "$('#fixed-1').offset().top" ); equals( $w('#fixed-1').offset().top, 1001, "jQuery('#fixed-1').offset().top" );
equals( $w('#fixed-1').offset().left, $.browser.msie ? 994 : 1001, "$('#fixed-1').offset().left" ); equals( $w('#fixed-1').offset().left, jQuery.browser.msie ? 994 : 1001, "jQuery('#fixed-1').offset().left" );
equals( $w('#fixed-2').offset().top, 1021, "$('#fixed-2').offset().top" ); equals( $w('#fixed-2').offset().top, 1021, "jQuery('#fixed-2').offset().top" );
equals( $w('#fixed-2').offset().left, $.browser.msie ? 1014 : 1021, "$('#fixed-2').offset().left" ); equals( $w('#fixed-2').offset().left, jQuery.browser.msie ? 1014 : 1021, "jQuery('#fixed-2').offset().left" );
testwin["fixed"].close(); testwin["fixed"].close();
}); });
@ -137,14 +137,14 @@ if ( !$.browser.msie || ($.browser.msie && parseInt($.browser.version) > 6) )
testwin("table", function() { testwin("table", function() {
var $w = testwin["table"].$; var $w = testwin["table"].$;
equals( $w('#table-1').offset().top, 6, "$('#table-1').offset().top" ); equals( $w('#table-1').offset().top, 6, "jQuery('#table-1').offset().top" );
equals( $w('#table-1').offset().left, 6, "$('#table-1').offset().left" ); equals( $w('#table-1').offset().left, 6, "jQuery('#table-1').offset().left" );
equals( $w('#th-1').offset().top, 10, "$('#table-1').offset().top" ); equals( $w('#th-1').offset().top, 10, "jQuery('#table-1').offset().top" );
equals( $w('#th-1').offset().left, 10, "$('#table-1').offset().left" ); equals( $w('#th-1').offset().left, 10, "jQuery('#table-1').offset().left" );
equals( $w('#th-2').offset().top, 10, "$('#table-1').offset().top" ); equals( $w('#th-2').offset().top, 10, "jQuery('#table-1').offset().top" );
equals( $w('#th-2').offset().left, 116, "$('#table-1').offset().left" ); equals( $w('#th-2').offset().left, 116, "jQuery('#table-1').offset().left" );
testwin["table"].close(); testwin["table"].close();
}); });
@ -153,12 +153,12 @@ testwin("scroll", function() {
var $w = testwin["scroll"].$; var $w = testwin["scroll"].$;
// IE is collapsing the top margin of 1px // IE is collapsing the top margin of 1px
equals( $w('#scroll-1').offset().top, $.browser.msie ? 6 : 7, "$('#scroll-1').offset().top" ); equals( $w('#scroll-1').offset().top, jQuery.browser.msie ? 6 : 7, "jQuery('#scroll-1').offset().top" );
equals( $w('#scroll-1').offset().left, 7, "$('#scroll-1').offset().left" ); equals( $w('#scroll-1').offset().left, 7, "jQuery('#scroll-1').offset().left" );
// IE is collapsing the top margin of 1px // IE is collapsing the top margin of 1px
equals( $w('#scroll-1-1').offset().top, $.browser.msie ? 9 : 11, "$('#scroll-1-1').offset().top" ); equals( $w('#scroll-1-1').offset().top, jQuery.browser.msie ? 9 : 11, "jQuery('#scroll-1-1').offset().top" );
equals( $w('#scroll-1-1').offset().left, 11, "$('#scroll-1-1').offset().left" ); equals( $w('#scroll-1-1').offset().left, 11, "jQuery('#scroll-1-1').offset().left" );
testwin["scroll"].close(); testwin["scroll"].close();
}); });

View file

@ -2,8 +2,8 @@ module("selector");
test("element", function() { test("element", function() {
expect(9); expect(9);
ok( $("*").size() >= 30, "Select all" ); ok( jQuery("*").size() >= 30, "Select all" );
var all = $("*"), good = true; var all = jQuery("*"), good = true;
for ( var i = 0; i < all.length; i++ ) for ( var i = 0; i < all.length; i++ )
if ( all[i].nodeType == 8 ) if ( all[i].nodeType == 8 )
good = false; good = false;
@ -12,18 +12,18 @@ test("element", function() {
t( "Element Selector", "body", ["body"] ); t( "Element Selector", "body", ["body"] );
t( "Element Selector", "html", ["html"] ); t( "Element Selector", "html", ["html"] );
t( "Parent Element", "div p", ["firstp","ap","sndp","en","sap","first"] ); t( "Parent Element", "div p", ["firstp","ap","sndp","en","sap","first"] );
equals( $("param", "#object1").length, 2, "Object/param as context" ); equals( jQuery("param", "#object1").length, 2, "Object/param as context" );
ok( $("#length").length, '&lt;input name="length"&gt; cannot be found under IE, see #945' ); ok( jQuery("#length").length, '&lt;input name="length"&gt; cannot be found under IE, see #945' );
ok( $("#lengthtest input").length, '&lt;input name="length"&gt; cannot be found under IE, see #945' ); ok( jQuery("#lengthtest input").length, '&lt;input name="length"&gt; cannot be found under IE, see #945' );
}); });
if ( location.protocol != "file:" ) { if ( location.protocol != "file:" ) {
test("Element Selector with underscore", function() { test("Element Selector with underscore", function() {
expect(1); expect(1);
stop(); stop();
$.get("data/with_fries.xml", function(xml) { jQuery.get("data/with_fries.xml", function(xml) {
equals( $("foo_bar", xml).length, 1, "Element Selector with underscore" ); equals( jQuery("foo_bar", xml).length, 1, "Element Selector with underscore" );
start(); start();
}); });
}); });
@ -66,14 +66,14 @@ test("id", function() {
t( "All Children of ID", "#foo > *", ["sndp", "en", "sap"] ); t( "All Children of ID", "#foo > *", ["sndp", "en", "sap"] );
t( "All Children of ID with no children", "#firstUL/*", [] ); t( "All Children of ID with no children", "#firstUL/*", [] );
$('<a name="tName1">tName1 A</a><a name="tName2">tName2 A</a><div id="tName1">tName1 Div</div>').appendTo('#main'); jQuery('<a name="tName1">tName1 A</a><a name="tName2">tName2 A</a><div id="tName1">tName1 Div</div>').appendTo('#main');
equals( $("#tName1")[0].id, 'tName1', "ID selector with same value for a name attribute" ); equals( jQuery("#tName1")[0].id, 'tName1', "ID selector with same value for a name attribute" );
equals( $("#tName2").length, 0, "ID selector non-existing but name attribute on an A tag" ); equals( jQuery("#tName2").length, 0, "ID selector non-existing but name attribute on an A tag" );
t( "ID Selector on Form with an input that has a name of 'id'", "#lengthtest", ["lengthtest"] ); t( "ID Selector on Form with an input that has a name of 'id'", "#lengthtest", ["lengthtest"] );
t( "ID selector with non-existant ancestor", "#asdfasdf #foobar", [] ); // bug #986 t( "ID selector with non-existant ancestor", "#asdfasdf #foobar", [] ); // bug #986
isSet( $("body").find("div#form"), [], "ID selector within the context of another element" ); isSet( jQuery("body").find("div#form"), [], "ID selector within the context of another element" );
}); });
test("class", function() { test("class", function() {