Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Support loading of jasmine more than once during a page load #249

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+47 −38
Split
View
@@ -5,7 +5,49 @@ var isCommonJS = typeof window == "undefined";
*
* @namespace
*/
-var jasmine = {};
+var initedBefore=!!window.jasmine;
+
+var jasmine = initedBefore? {
+ setTimeout:jasmine.setTimeout,
+ clearTimeout:jasmine.clearTimeout,
+ setInterval:jasmine.setInterval,
+ clearInterval:jasmine.clearInterval
+
+} : {};
+
+/**
+ * Allows for bound functions to be compared. Internal use only.
+ *
+ * @ignore
+ * @private
+ * @param base {Object} bound 'this' for the function
+ * @param name {Function} function to find
+ */
+jasmine.bindOriginal_ = function(base, name) {
+ var original = base[name];
+ if (original.apply) {
+ return function() {
+ return original.apply(base, arguments);
+ };
+ } else {
+ // IE support
+ return jasmine.getGlobal()[name];
+ }
+};
+
+jasmine.getGlobal = function() {
+ function getGlobal() {
+ return this;
+ }
+
+ return getGlobal();
+};
+if (!initedBefore){
+ jasmine.setTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'setTimeout');
+ jasmine.clearTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'clearTimeout');
+ jasmine.setInterval = jasmine.bindOriginal_(jasmine.getGlobal(), 'setInterval');
+ jasmine.clearInterval = jasmine.bindOriginal_(jasmine.getGlobal(), 'clearInterval');
+}
if (isCommonJS) exports.jasmine = jasmine;
/**
* @private
@@ -46,39 +88,6 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
*/
jasmine.CATCH_EXCEPTIONS = true;
-jasmine.getGlobal = function() {
- function getGlobal() {
- return this;
- }
-
- return getGlobal();
-};
-
-/**
- * Allows for bound functions to be compared. Internal use only.
- *
- * @ignore
- * @private
- * @param base {Object} bound 'this' for the function
- * @param name {Function} function to find
- */
-jasmine.bindOriginal_ = function(base, name) {
- var original = base[name];
- if (original.apply) {
- return function() {
- return original.apply(base, arguments);
- };
- } else {
- // IE support
- return jasmine.getGlobal()[name];
- }
-};
-
-jasmine.setTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'setTimeout');
-jasmine.clearTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'clearTimeout');
-jasmine.setInterval = jasmine.bindOriginal_(jasmine.getGlobal(), 'setInterval');
-jasmine.clearInterval = jasmine.bindOriginal_(jasmine.getGlobal(), 'clearInterval');
-
jasmine.MessageResult = function(values) {
this.type = 'log';
this.values = values;
View
@@ -128,10 +128,10 @@ jasmine.Clock = {
},
real: {
- setTimeout: jasmine.getGlobal().setTimeout,
- clearTimeout: jasmine.getGlobal().clearTimeout,
- setInterval: jasmine.getGlobal().setInterval,
- clearInterval: jasmine.getGlobal().clearInterval
+ setTimeout: jasmine.setTimeout,
+ clearTimeout: jasmine.clearTimeout,
+ setInterval: jasmine.setInterval,
+ clearInterval: jasmine.clearInterval
},
assertInstalled: function() {