Move clock from global to jasmine; provide a function to access the clock.

This commit is contained in:
Davis W. Frank
2013-10-10 16:24:58 -07:00
parent c28c124f58
commit 5aaafed4d8
5 changed files with 42 additions and 19 deletions
+7 -2
View File
@@ -91,8 +91,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
return env.spyOn(obj, methodName); return env.spyOn(obj, methodName);
}, },
clock: env.clock,
addCustomEqualityTester: function(tester) { addCustomEqualityTester: function(tester) {
env.addCustomEqualityTester(tester); env.addCustomEqualityTester(tester);
}, },
@@ -125,6 +123,13 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
return env.addMatchers(matchers); return env.addMatchers(matchers);
}; };
/**
* Expose the mock interface for the JavaScript timeout functions
*/
jasmine.clock = function() {
return env.clock;
};
/** /**
* ## Runner Parameters * ## Runner Parameters
* *
+7 -2
View File
@@ -69,8 +69,6 @@
return env.spyOn(obj, methodName); return env.spyOn(obj, methodName);
}, },
clock: env.clock,
addCustomEqualityTester: function(tester) { addCustomEqualityTester: function(tester) {
env.addCustomEqualityTester(tester); env.addCustomEqualityTester(tester);
}, },
@@ -103,6 +101,13 @@
return env.addMatchers(matchers); return env.addMatchers(matchers);
}; };
/**
* Expose the mock interface for the JavaScript timeout functions
*/
jasmine.clock = function() {
return env.clock;
};
/** /**
* ## Runner Parameters * ## Runner Parameters
* *
+4 -4
View File
@@ -67,7 +67,7 @@ describe("QueueRunner", function() {
onComplete: onComplete onComplete: onComplete
}); });
clock.install(); jasmine.clock().install();
queueRunner.execute(); queueRunner.execute();
@@ -76,18 +76,18 @@ describe("QueueRunner", function() {
expect(afterCallback).not.toHaveBeenCalled(); expect(afterCallback).not.toHaveBeenCalled();
expect(onComplete).not.toHaveBeenCalled(); expect(onComplete).not.toHaveBeenCalled();
clock.tick(100); jasmine.clock().tick(100);
expect(fnCallback).toHaveBeenCalled(); expect(fnCallback).toHaveBeenCalled();
expect(afterCallback).not.toHaveBeenCalled(); expect(afterCallback).not.toHaveBeenCalled();
expect(onComplete).not.toHaveBeenCalled(); expect(onComplete).not.toHaveBeenCalled();
clock.tick(100); jasmine.clock().tick(100);
expect(afterCallback).toHaveBeenCalled(); expect(afterCallback).toHaveBeenCalled();
expect(onComplete).not.toHaveBeenCalled(); expect(onComplete).not.toHaveBeenCalled();
clock.tick(100); jasmine.clock().tick(100);
expect(onComplete).toHaveBeenCalled(); expect(onComplete).toHaveBeenCalled();
}); });
+12 -10
View File
@@ -41,20 +41,10 @@ var jasmineInterface = {
return env.expect(actual); return env.expect(actual);
}, },
addMatchers: function(matchers) {
return env.addMatchers(matchers);
},
spyOn: function(obj, methodName) { spyOn: function(obj, methodName) {
return env.spyOn(obj, methodName); return env.spyOn(obj, methodName);
}, },
clock: env.clock,
setTimeout: env.clock.setTimeout,
clearTimeout: env.clock.clearTimeout,
setInterval: env.clock.setInterval,
clearInterval: env.clock.clearInterval,
jsApiReporter: new jasmine.JsApiReporter({ jsApiReporter: new jasmine.JsApiReporter({
timer: new jasmine.Timer() timer: new jasmine.Timer()
}) })
@@ -67,6 +57,18 @@ function extend(destination, source) {
return destination; return destination;
} }
jasmine.addCustomEqualityTester = function(tester) {
env.addCustomEqualityTester(tester);
};
jasmine.addMatchers = function(matchers) {
return env.addMatchers(matchers);
};
jasmine.clock = function() {
return env.clock;
};
// Jasmine "runner" // Jasmine "runner"
function executeSpecs(specs, done, isVerbose, showColors) { function executeSpecs(specs, done, isVerbose, showColors) {
global.jasmine = jasmine; global.jasmine = jasmine;
+12 -1
View File
@@ -47,7 +47,6 @@
return env.spyOn(obj, methodName); return env.spyOn(obj, methodName);
}, },
clock: env.clock,
jsApiReporter: new jasmine.JsApiReporter({ jsApiReporter: new jasmine.JsApiReporter({
timer: new jasmine.Timer() timer: new jasmine.Timer()
}) })
@@ -59,6 +58,18 @@
extend(window, jasmineInterface); extend(window, jasmineInterface);
} }
jasmine.addCustomEqualityTester = function(tester) {
env.addCustomEqualityTester(tester);
};
jasmine.addMatchers = function(matchers) {
return env.addMatchers(matchers);
};
jasmine.clock = function() {
return env.clock;
};
var queryString = new jasmine.QueryString({ var queryString = new jasmine.QueryString({
getWindowLocation: function() { return window.location; } getWindowLocation: function() { return window.location; }
}); });