/* */
(function(process) {
module("core", {teardown: moduleTeardown});
test("Unit Testing Environment", function() {
expect(1);
ok(!isLocal, "Unit tests shouldn't be run from file://, especially in Chrome. If you must test from file:// with Chrome, run it with the --allow-file-access-from-files flag!");
});
test("Basic requirements", function() {
expect(7);
ok(Array.prototype.push, "Array.push()");
ok(Function.prototype.apply, "Function.apply()");
ok(document.getElementById, "getElementById");
ok(document.getElementsByTagName, "getElementsByTagName");
ok(RegExp, "RegExp");
ok(jQuery, "jQuery");
ok($, "$");
});
test("jQuery()", function() {
var elem,
i,
obj = jQuery("div"),
main = jQuery("#qunit-fixture"),
code = jQuery(""),
img = jQuery(""),
div = jQuery("
"),
exec = false,
lng = "",
expected = 26,
attrObj = {
"click": function() {
ok(exec, "Click executed.");
},
"text": "test",
"class": "test2",
"id": "test3"
};
if (jQuery.fn.width) {
expected++;
attrObj["width"] = 10;
}
if (jQuery.fn.offset) {
expected++;
attrObj["offset"] = {
"top": 1,
"left": 1
};
}
if (jQuery.fn.css) {
expected += 2;
attrObj["css"] = {
"paddingLeft": 1,
"paddingRight": 1
};
}
if (jQuery.fn.attr) {
expected++;
attrObj.attr = {"desired": "very"};
}
expect(expected);
equal(jQuery().length, 0, "jQuery() === jQuery([])");
equal(jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])");
equal(jQuery(null).length, 0, "jQuery(null) === jQuery([])");
equal(jQuery("").length, 0, "jQuery('') === jQuery([])");
equal(jQuery("#").length, 0, "jQuery('#') === jQuery([])");
equal(jQuery(obj).selector, "div", "jQuery(jQueryObj) == jQueryObj");
equal(jQuery(window).length, 1, "Correct number of elements generated for jQuery(window)");
deepEqual(jQuery("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context");
equal(code.length, 1, "Correct number of elements generated for code");
equal(code.parent().length, 0, "Make sure that the generated HTML has no parent.");
equal(img.length, 1, "Correct number of elements generated for img");
equal(img.parent().length, 0, "Make sure that the generated HTML has no parent.");
equal(div.length, 4, "Correct number of elements generated for div hr code b");
equal(div.parent().length, 0, "Make sure that the generated HTML has no parent.");
equal(jQuery([1, 2, 3]).get(1), 2, "Test passing an array to the factory");
equal(jQuery(document.body).get(0), jQuery("body").get(0), "Test passing an html node to the factory");
elem = jQuery("", attrObj);
if (jQuery.fn.width) {
equal(elem[0].style.width, "10px", "jQuery() quick setter width");
}
if (jQuery.fn.offset) {
equal(elem[0].style.top, "1px", "jQuery() quick setter offset");
}
if (jQuery.fn.css) {
equal(elem[0].style.paddingLeft, "1px", "jQuery quick setter css");
equal(elem[0].style.paddingRight, "1px", "jQuery quick setter css");
}
if (jQuery.fn.attr) {
equal(elem[0].getAttribute("desired"), "very", "jQuery quick setter attr");
}
equal(elem[0].childNodes.length, 1, "jQuery quick setter text");
equal(elem[0].firstChild.nodeValue, "test", "jQuery quick setter text");
equal(elem[0].className, "test2", "jQuery() quick setter class");
equal(elem[0].id, "test3", "jQuery() quick setter id");
exec = true;
elem.click();
elem.remove();
for (i = 0; i < 3; ++i) {
elem = jQuery("");
}
equal(elem[0].defaultValue, "TEST", "Ensure cached nodes are cloned properly (Bug #6655)");
elem.remove();
equal(jQuery(" ").length, 1, "Make sure whitespace is trimmed.");
equal(jQuery(" ab ").length, 1, "Make sure whitespace and other characters are trimmed.");
for (i = 0; i < 128; i++) {
lng += "12345678";
}
equal(jQuery(" some p
\nmore text\r\nA well-formed xml string
"); tmp = xml.getElementsByTagName("p")[0]; ok(!!tmp, "present in document"); tmp = tmp.getElementsByTagName("b")[0]; ok(!!tmp, " present in document"); strictEqual(tmp.childNodes[0].nodeValue, "well-formed", " text is as expected"); } catch (e) { strictEqual(e, undefined, "unexpected error"); } try { xml = jQuery.parseXML("
Not a <well-formed xml string
"); ok(false, "invalid xml not detected"); } catch (e) { strictEqual(e.message, "Invalid XML:Not a <well-formed xml string
", "invalid xml detected"); } try { xml = jQuery.parseXML(""); strictEqual(xml, null, "empty string => null document"); xml = jQuery.parseXML(); strictEqual(xml, null, "undefined string => null document"); xml = jQuery.parseXML(null); strictEqual(xml, null, "null string => null document"); xml = jQuery.parseXML(true); strictEqual(xml, null, "non-string => null document"); } catch (e) { ok(false, "empty input throws exception"); } }); if (jQuery.sub) { test("jQuery.sub() - Static Methods", function() { expect(18); var Subclass = jQuery.sub(); Subclass.extend({ "topLevelMethod": function() { return this.debug; }, "debug": false, "config": {"locale": "en_US"}, "setup": function(config) { this.extend(true, this["config"], config); } }); Subclass.fn.extend({"subClassMethod": function() { return this; }}); ok(Subclass["topLevelMethod"]() === false, "Subclass.topLevelMethod thought debug was true"); ok(Subclass["config"]["locale"] == "en_US", Subclass["config"]["locale"] + " is wrong!"); deepEqual(Subclass["config"]["test"], undefined, "Subclass.config.test is set incorrectly"); equal(jQuery.ajax, Subclass.ajax, "The subclass failed to get all top level methods"); var SubSubclass = Subclass.sub(); ok(SubSubclass["topLevelMethod"]() === false, "SubSubclass.topLevelMethod thought debug was true"); ok(SubSubclass["config"]["locale"] == "en_US", SubSubclass["config"]["locale"] + " is wrong!"); deepEqual(SubSubclass["config"]["test"], undefined, "SubSubclass.config.test is set incorrectly"); equal(jQuery.ajax, SubSubclass.ajax, "The subsubclass failed to get all top level methods"); SubSubclass.fn.extend({"subSubClassMethod": function() { return this; }}); SubSubclass["setup"]({ "locale": "es_MX", "test": "worked" }); SubSubclass["debug"] = true; SubSubclass.ajax = function() { return false; }; ok(SubSubclass["topLevelMethod"](), "SubSubclass.topLevelMethod thought debug was false"); deepEqual(SubSubclass(document)["subClassMethod"], Subclass.fn["subClassMethod"], "Methods Differ!"); ok(SubSubclass["config"]["locale"] == "es_MX", SubSubclass["config"]["locale"] + " is wrong!"); ok(SubSubclass["config"]["test"] == "worked", "SubSubclass.config.test is set incorrectly"); notEqual(jQuery.ajax, SubSubclass.ajax, "The subsubclass failed to get all top level methods"); ok(Subclass["topLevelMethod"]() === false, "Subclass.topLevelMethod thought debug was true"); ok(Subclass["config"]["locale"] == "en_US", Subclass["config"]["locale"] + " is wrong!"); deepEqual(Subclass["config"]["test"], undefined, "Subclass.config.test is set incorrectly"); deepEqual(Subclass(document)["subSubClassMethod"], undefined, "subSubClassMethod set incorrectly"); equal(jQuery.ajax, Subclass.ajax, "The subclass failed to get all top level methods"); }); test("jQuery.sub() - .fn Methods", function() { expect(378); var Subclass = jQuery.sub(), SubclassSubclass = Subclass.sub(), jQueryDocument = jQuery(document), selectors, contexts, methods, method, arg, description; jQueryDocument.toString = function() { return "jQueryDocument"; }; Subclass.fn.subclassMethod = function() {}; SubclassSubclass.fn.subclassSubclassMethod = function() {}; selectors = ["body", "html, body", ""]; contexts = [undefined, document, jQueryDocument]; jQuery.expandedEach = jQuery.each; jQuery.each(selectors, function(i, selector) { jQuery.expandedEach({ "eq": 1, "add": document, "end": undefined, "has": undefined, "closest": "div", "filter": document, "find": "div" }, function(method, arg) { jQuery.each(contexts, function(i, context) { description = "(\"" + selector + "\", " + context + ")." + method + "(" + (arg || "") + ")"; deepEqual((function(var_args) { return jQuery.fn[method].apply(jQuery(selector, context), arguments).subclassMethod; })(arg), undefined, "jQuery" + description + " doesn't have Subclass methods"); deepEqual((function(var_args) { return jQuery.fn[method].apply(jQuery(selector, context), arguments).subclassSubclassMethod; })(arg), undefined, "jQuery" + description + " doesn't have SubclassSubclass methods"); deepEqual(Subclass(selector, context)[method](arg).subclassMethod, Subclass.fn.subclassMethod, "Subclass" + description + " has Subclass methods"); deepEqual(Subclass(selector, context)[method](arg).subclassSubclassMethod, undefined, "Subclass" + description + " doesn't have SubclassSubclass methods"); deepEqual(SubclassSubclass(selector, context)[method](arg).subclassMethod, Subclass.fn.subclassMethod, "SubclassSubclass" + description + " has Subclass methods"); deepEqual(SubclassSubclass(selector, context)[method](arg).subclassSubclassMethod, SubclassSubclass.fn.subclassSubclassMethod, "SubclassSubclass" + description + " has SubclassSubclass methods"); }); }); }); }); } test("jQuery.camelCase()", function() { var tests = { "foo-bar": "fooBar", "foo-bar-baz": "fooBarBaz", "girl-u-want": "girlUWant", "the-4th-dimension": "the4thDimension", "-o-tannenbaum": "OTannenbaum", "-moz-illa": "MozIlla", "-ms-take": "msTake" }; expect(7); jQuery.each(tests, function(key, val) { equal(jQuery.camelCase(key), val, "Converts: " + key + " => " + val); }); }); })(require("process"));