Re-add Mock Clock behavior as global 'clock'

- Use clock.install, clock.tick...
- Add unit coverage.
- Fixes old bug in function scheduler
This commit is contained in:
Davis W. Frank & Rajan Agaskar
2012-12-06 18:22:46 -08:00
parent a1011e7748
commit 74f928fd54
19 changed files with 1074 additions and 464 deletions
+30
View File
@@ -157,3 +157,33 @@ describe("jasmine.Env", function() {
});
});
});
describe("jasmine Env", function() {
it("Mock clock can be installed and used in tests", function() {
var setTimeout = jasmine.createSpy('setTimeout'),
globalTimeoutFn = jasmine.createSpy('globalTimeoutFn'),
fakeTimeoutFn = jasmine.createSpy('fakeTimeoutFn'),
env = new jasmine.Env({global: { setTimeout: setTimeout }});
env.describe("tests", function() {
env.it("test with mock clock", function() {
env.clock.install();
env.clock.setTimeout(fakeTimeoutFn, 100);
env.clock.tick(100);
});
env.it("test without mock clock", function() {
env.clock.setTimeout(globalTimeoutFn, 100);
});
});
expect(setTimeout).not.toHaveBeenCalled();
expect(fakeTimeoutFn).not.toHaveBeenCalled();
env.execute();
expect(fakeTimeoutFn).toHaveBeenCalled();
expect(setTimeout).toHaveBeenCalledWith(globalTimeoutFn, 100);
});
});