Skip to content
Permalink
Browse files

Added a fix for .noConflict(true) not reverting properly. Also added …

…unit tests for noConflict.
  • Loading branch information
jeresig committed Oct 20, 2007
1 parent 5736e8d commit 1ac9d6fbeed214d59ea5c31a87ff2c19bb08dbc8
Showing with 26 additions and 4 deletions.
  1. +4 −4 src/core.js
  2. +1 −0 test/index.html
  3. +21 −0 test/unit/core.js
@@ -10,8 +10,8 @@
*/

// Map over jQuery in case of overwrite
if ( typeof jQuery != "undefined" )
var _jQuery = jQuery;
if ( window.jQuery )
var _jQuery = window.jQuery;

var jQuery = window.jQuery = function( selector, context ) {
// If the context is a namespace object, return a new object
@@ -21,8 +21,8 @@ var jQuery = window.jQuery = function( selector, context ) {
};

// Map over the $ in case of overwrite
if ( typeof $ != "undefined" )
var _$ = $;
if ( window.$ )
var _$ = window.$;

// Map the jQuery namespace to the '$' one
window.$ = jQuery;
@@ -4,6 +4,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery Test Suite</title>
<link rel="Stylesheet" media="screen" href="data/testsuite.css" />
<script>var jQuery = "jQuery", $ = "$"; // For testing .noConflcit()</script>
<script type="text/javascript" src="../dist/jquery.js"></script>
<script type="text/javascript" src="data/testrunner.js"></script>
<script type="text/javascript" src="unit/core.js"></script>
@@ -38,6 +38,27 @@ test("$()", function() {
equals( div.length, 4, "Correct number of elements generated for div hr code b" );
});

test("noConflict", function() {
expect(6);

var old = jQuery;
var newjQuery = jQuery.noConflict();

ok( newjQuery == old, "noConflict returned the jQuery object" );
ok( jQuery == old, "Make sure jQuery wasn't touched." );
ok( $ == "$", "Make sure $ was reverted." );

jQuery = $ = old;

newjQuery = jQuery.noConflict(true);

ok( newjQuery == old, "noConflict returned the jQuery object" );
ok( jQuery == "jQuery", "Make sure jQuery was reverted." );
ok( $ == "$", "Make sure $ was reverted." );

jQuery = $ = old;
});

test("isFunction", function() {
expect(21);

0 comments on commit 1ac9d6f

Please sign in to comment.
You can’t perform that action at this time.