dwf: finished ExceptionsTest.js - BOOTSTRAP is red, not sure why

This commit is contained in:
Davis W. Frank 2009-06-15 13:47:05 -07:00
parent 6a2602f243
commit a5cf424f08
2 changed files with 68 additions and 113 deletions

115
spec/bootstrap.js vendored
View File

@ -148,114 +148,6 @@ var testHandlesBlankSpecs = function () {
'Should have found 2 passing specs, got ' + runner.suites[0].results.passedCount);
};
var testFormatsExceptionMessages = function () {
var sampleFirefoxException = {
fileName: 'foo.js',
line: '1978',
message: 'you got your foo in my bar',
name: 'A Classic Mistake'
};
var sampleWebkitException = {
sourceURL: 'foo.js',
lineNumber: '1978',
message: 'you got your foo in my bar',
name: 'A Classic Mistake'
};
var expected = 'A Classic Mistake: you got your foo in my bar in foo.js (line 1978)';
reporter.test((jasmine.util.formatException(sampleFirefoxException) === expected),
'Should have got ' + expected + ' but got: ' + jasmine.util.formatException(sampleFirefoxException));
reporter.test((jasmine.util.formatException(sampleWebkitException) === expected),
'Should have got ' + expected + ' but got: ' + jasmine.util.formatException(sampleWebkitException));
};
var testHandlesExceptions = function () {
var env = newJasmineEnv();
//we run two exception tests to make sure we continue after throwing an exception
var suite = env.describe('Suite for handles exceptions', function () {
env.it('should be a test that fails because it throws an exception', function() {
this.runs(function () {
throw new Error('fake error 1');
});
});
env.it('should be another test that fails because it throws an exception', function() {
this.runs(function () {
throw new Error('fake error 2');
});
this.runs(function () {
this.expect(true).toEqual(true);
});
});
env.it('should be a passing test that runs after exceptions are thrown', function() {
this.runs(function () {
this.expect(true).toEqual(true);
});
});
env.it('should be another test that fails because it throws an exception after a wait', function() {
this.runs(function () {
var foo = 'foo';
});
this.waits(250);
this.runs(function () {
throw new Error('fake error 3');
});
});
env.it('should be a passing test that runs after exceptions are thrown from a async test', function() {
this.runs(function () {
this.expect(true).toEqual(true);
});
});
});
var runner = env.currentRunner;
runner.execute();
Clock.tick(400); //TODO: setting this to a large number causes failures, but shouldn't
var resultsForSpec0 = suite.specs[0].getResults();
var resultsForSpec1 = suite.specs[1].getResults();
var resultsForSpec2 = suite.specs[2].getResults();
var resultsForSpec3 = suite.specs[3].getResults();
reporter.test((suite.getResults().totalCount == 6),
'Should have found 5 spec results, got ' + suite.getResults().totalCount);
reporter.test((resultsForSpec0.getItems()[0].passed === false),
'Spec1 test, expectation 0 should have failed, got passed');
reporter.test((resultsForSpec0.getItems()[0].message.match(/fake error 1/)),
'Spec1 test, expectation 0 should have a message that contained /fake error 1/, got ' + resultsForSpec0.getItems()[0].message);
reporter.test((resultsForSpec1.getItems()[0].passed === false),
'Spec2 test, expectation 0 should have failed, got passed');
reporter.test((resultsForSpec1.getItems()[0].message.match(/fake error 2/)),
'Spec2 test, expectation 0 should have a message that contained /fake error 2/, got ' + resultsForSpec1.getItems()[0].message);
reporter.test((resultsForSpec1.getItems()[1].passed === true),
'Spec2 test should have had a passing 2nd expectation');
reporter.test((resultsForSpec2.getItems()[0].passed === true),
'Spec3 test should have passed, got failed');
reporter.test((resultsForSpec3.getItems()[0].passed === false),
'Spec3 test should have a failing first expectation, got passed');
reporter.test((resultsForSpec3.getItems()[0].message.match(/fake error 3/)),
'Spec3 test should have an error message that contained /fake error 3/, got ' + resultsForSpec3.getItems()[0].message);
};
var testResultsAliasing = function () {
var env = newJasmineEnv();
@ -283,10 +175,9 @@ var runTests = function () {
runSuite('RunnerTest.js');
runSuite('JsonReporterTest.js');
runSuite('SpyTest.js');
testFormatsExceptionMessages();
testHandlesExceptions();
testResultsAliasing();
runSuite('ExceptionsTest.js');
// testResultsAliasing(); // this appears to do nothing.
// handle blank specs will work later.
// testHandlesBlankSpecs();

View File

@ -31,4 +31,68 @@ describe('Exceptions:', function() {
expect(jasmine.util.formatException(sampleWebkitException)).toEqual(expected);
});
});
it('should handle exceptions thrown, but continue', function() {
var fakeTimer = new jasmine.FakeTimer();
env.setTimeout = fakeTimer.setTimeout;
env.clearTimeout = fakeTimer.clearTimeout;
env.setInterval = fakeTimer.setInterval;
env.clearInterval = fakeTimer.clearInterval;
//we run two exception tests to make sure we continue after throwing an exception
var suite = env.describe('Suite for handles exceptions', function () {
env.it('should be a test that fails because it throws an exception', function() {
throw new Error('fake error 1');
});
env.it('should be another test that fails because it throws an exception', function() {
this.runs(function () {
throw new Error('fake error 2');
});
this.runs(function () {
this.expect(true).toEqual(true);
});
});
env.it('should be a passing test that runs after exceptions are thrown', function() {
this.expect(true).toEqual(true);
});
env.it('should be another test that fails because it throws an exception after a wait', function() {
this.runs(function () {
var foo = 'foo';
});
this.waits(250);
this.runs(function () {
throw new Error('fake error 3');
});
});
env.it('should be a passing test that runs after exceptions are thrown from a async test', function() {
this.expect(true).toEqual(true);
});
});
var runner = env.currentRunner;
suite.execute();
fakeTimer.tick(300); //TODO: setting this to a large number causes failures, but shouldn't
var resultsForSpec0 = suite.specs[0].getResults();
var resultsForSpec1 = suite.specs[1].getResults();
var resultsForSpec2 = suite.specs[2].getResults();
var resultsForSpec3 = suite.specs[3].getResults();
expect(suite.getResults().totalCount).toEqual(6);
expect(resultsForSpec0.getItems()[0].passed).toEqual(false);
expect(resultsForSpec0.getItems()[0].message).toMatch(/fake error 1/);
expect(resultsForSpec1.getItems()[0].passed).toEqual(false),
expect(resultsForSpec1.getItems()[0].message).toMatch(/fake error 2/),
expect(resultsForSpec1.getItems()[1].passed).toEqual(true);
expect(resultsForSpec2.getItems()[0].passed).toEqual(true);
expect(resultsForSpec3.getItems()[0].passed).toEqual(false);
expect(resultsForSpec3.getItems()[0].message).toMatch(/fake error 3/);
});
});