[Finishes #45476285] Add timeout support to async tests

This commit is contained in:
Colin O'Byrne and JR Boyens
2013-07-23 16:43:42 -07:00
parent 9609aba25f
commit 8f5d0beb8c
6 changed files with 95 additions and 8 deletions

View File

@@ -291,6 +291,55 @@ describe("Env integration", function() {
env.execute();
});
describe("with a mock clock", function() {
beforeEach(function() {
jasmine.getEnv().clock.install();
});
afterEach(function() {
jasmine.getEnv().clock.uninstall();
});
it("should not hang on async specs that forget to call done()", function(done) {
var env = new j$.Env(),
reporter = jasmine.createSpyObj('fakeReporter', [
"jasmineStarted",
"jasmineDone",
"suiteStarted",
"suiteDone",
"specStarted",
"specDone"
]);
env.addReporter(reporter);
env.describe("tests", function() {
env.it("async spec that will hang", function(underTestCallback) {
env.expect(true).toBeTruthy();
});
env.it("after async spec", function() {
env.expect(true).toBeTruthy();
});
});
env.execute();
reporter.jasmineDone.and.callFake(function() {
expect(reporter.jasmineStarted).toHaveBeenCalledWith({
totalSpecsDefined: 2
});
expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({status: 'passed'}));
expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({status: 'failed'}));
done();
});
jasmine.getEnv().clock.tick(60001);
});
});
// TODO: something is wrong with this spec
it("should report as expected", function(done) {

View File

@@ -15,6 +15,8 @@ describe('Spies', function () {
});
it("warns the user that we indend to overwrite an existing property", function() {
TestClass.prototype.someFunction.and = "existing";
expect(function() {
j$.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
}).toThrowError("Jasmine spies would overwrite the 'and' and 'calls' properties on the object being spied upon");
@@ -23,8 +25,8 @@ describe('Spies', function () {
it("adds a spyStrategy and callTracker to the spy", function() {
var spy = j$.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
expect(spy.and).toEqual(jasmine.any(j$.SpyStrategy);
expect(spy.calls).toEqual(jasmine.any(j$.CallTracker);
expect(spy.and).toEqual(jasmine.any(j$.SpyStrategy));
expect(spy.calls).toEqual(jasmine.any(j$.CallTracker));
});
});

View File

@@ -6,6 +6,9 @@
var env = jasmine.getEnv();
SUPER_TIMEOUT = setTimeout;
SUPER_CLEAR_TIMEOUT = clearTimeout;
var jasmineInterface = {
describe: function(description, specDefinitions) {
return env.describe(description, specDefinitions);