Remove results from Queue
- consequently, Runner & Suite no longer have results. - Results come back to reporters from Spec, we should not have a need to walk them later via suite/runner (in fact, no reporter used results on suite/runner -- only bad tests) - Remove/clean up tests relying on #results - Remove integration tests that duplicate already tested behavior
This commit is contained in:
@@ -59,117 +59,36 @@ describe('Exceptions:', function() {
|
||||
|
||||
describe("with catch on exception", function() {
|
||||
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 () {
|
||||
var ranSecondTest = false,
|
||||
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');
|
||||
throw new Error();
|
||||
});
|
||||
|
||||
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);
|
||||
ranSecondTest = true;
|
||||
});
|
||||
});
|
||||
|
||||
var runner = env.currentRunner();
|
||||
suite.execute();
|
||||
fakeTimer.tick(2500);
|
||||
|
||||
var suiteResults = suite.results();
|
||||
var specResults = suiteResults.getItems();
|
||||
|
||||
expect(suiteResults.passed()).toEqual(false);
|
||||
//
|
||||
expect(specResults.length).toEqual(5);
|
||||
expect(specResults[0].passed()).toMatch(false);
|
||||
var blockResults = specResults[0].getItems();
|
||||
expect(blockResults[0].passed).toEqual(false);
|
||||
expect(blockResults[0].message).toMatch(/fake error 1/);
|
||||
|
||||
expect(specResults[1].passed()).toEqual(false);
|
||||
blockResults = specResults[1].getItems();
|
||||
expect(blockResults[0].passed).toEqual(false);
|
||||
expect(blockResults[0].message).toMatch(/fake error 2/);
|
||||
expect(blockResults[1].passed).toEqual(true);
|
||||
|
||||
expect(specResults[2].passed()).toEqual(true);
|
||||
|
||||
expect(specResults[3].passed()).toEqual(false);
|
||||
blockResults = specResults[3].getItems();
|
||||
expect(blockResults[0].message).toMatch(/fake error 3/);
|
||||
|
||||
expect(specResults[4].passed()).toEqual(true);
|
||||
expect(ranSecondTest).toBe(true);
|
||||
});
|
||||
|
||||
it("should handle exceptions thrown directly in top-level describe blocks and continue", function () {
|
||||
var suite = env.describe("a top level describe block that throws an exception", function () {
|
||||
var ranSecondDescribe = false, suite, suite2, runner = env.currentRunner();
|
||||
suite = env.describe("a suite that throws an exception", function () {
|
||||
env.it("is a test that should pass", function () {
|
||||
this.expect(true).toEqual(true);
|
||||
});
|
||||
|
||||
throw new Error("top level error");
|
||||
});
|
||||
|
||||
suite.execute();
|
||||
var suiteResults = suite.results();
|
||||
var specResults = suiteResults.getItems();
|
||||
|
||||
expect(suiteResults.passed()).toEqual(false);
|
||||
expect(specResults.length).toEqual(2);
|
||||
|
||||
expect(specResults[1].description).toMatch(/encountered a declaration exception/);
|
||||
});
|
||||
|
||||
it("should handle exceptions thrown directly in nested describe blocks and continue", function () {
|
||||
var suite = env.describe("a top level describe", function () {
|
||||
env.describe("a mid-level describe that throws an exception", function () {
|
||||
env.it("is a test that should pass", function () {
|
||||
this.expect(true).toEqual(true);
|
||||
});
|
||||
|
||||
throw new Error("a mid-level error");
|
||||
});
|
||||
suite2 = env.describe("a suite that doesn't throw an exception", function () {
|
||||
ranSecondDescribe = true;
|
||||
});
|
||||
|
||||
suite.execute();
|
||||
var suiteResults = suite.results();
|
||||
var specResults = suiteResults.getItems();
|
||||
|
||||
expect(suiteResults.passed()).toEqual(false);
|
||||
expect(specResults.length).toEqual(1);
|
||||
|
||||
var nestedSpecResults = specResults[0].getItems();
|
||||
|
||||
expect(nestedSpecResults.length).toEqual(2);
|
||||
expect(nestedSpecResults[1].description).toMatch(/encountered a declaration exception/);
|
||||
runner.execute();
|
||||
expect(ranSecondDescribe).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -14,105 +14,83 @@ describe('RunnerTest', function() {
|
||||
});
|
||||
|
||||
describe('beforeEach', function() {
|
||||
it('should run before each spec for all suites', function () {
|
||||
it('should run before each spec for all suites', function() {
|
||||
var foo;
|
||||
env.beforeEach(function () {
|
||||
env.beforeEach(function() {
|
||||
foo = 0;
|
||||
});
|
||||
|
||||
env.describe('suite 1', function () {
|
||||
env.describe('suite 1', function() {
|
||||
env.it('test 1-1', function() {
|
||||
foo++;
|
||||
this.expect(foo).toEqual(1);
|
||||
expect(foo).toEqual(1);
|
||||
});
|
||||
env.it('test 1-2', function() {
|
||||
foo++;
|
||||
this.expect(foo).toEqual(1);
|
||||
expect(foo).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
env.describe('suite 2', function () {
|
||||
env.describe('suite 2', function() {
|
||||
env.it('test 2-1', function() {
|
||||
foo++;
|
||||
this.expect(foo).toEqual(1);
|
||||
expect(foo).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
env.currentRunner().execute();
|
||||
|
||||
var runnerResults = env.currentRunner().results();
|
||||
expect(runnerResults.totalCount).toEqual(3);
|
||||
expect(runnerResults.passedCount).toEqual(3);
|
||||
});
|
||||
|
||||
it('should provide all specs', function() {
|
||||
|
||||
it('should provide all specs', function () {
|
||||
var foo;
|
||||
env.beforeEach(function () {
|
||||
foo = 0;
|
||||
});
|
||||
|
||||
env.describe('suite 1', function () {
|
||||
env.describe('suite 1', function() {
|
||||
env.it('test 1-1', function() {
|
||||
foo++;
|
||||
this.expect(foo).toEqual(1);
|
||||
});
|
||||
env.it('test 1-2', function() {
|
||||
foo++;
|
||||
this.expect(foo).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
env.describe('suite 2', function () {
|
||||
env.describe('suite 2', function() {
|
||||
env.it('test 2-1', function() {
|
||||
foo++;
|
||||
this.expect(foo).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
env.currentRunner().execute();
|
||||
|
||||
|
||||
expect(env.currentRunner().specs().length).toEqual(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('afterEach', function() {
|
||||
it('should run after each spec for all suites', function () {
|
||||
it('should run after each spec for all suites', function() {
|
||||
var foo = 3;
|
||||
env.afterEach(function () {
|
||||
env.afterEach(function() {
|
||||
foo = foo - 1;
|
||||
});
|
||||
|
||||
env.describe('suite 1', function () {
|
||||
env.describe('suite 1', function() {
|
||||
env.it('test 1-1', function() {
|
||||
this.expect(foo).toEqual(3);
|
||||
expect(foo).toEqual(3);
|
||||
});
|
||||
env.it('test 1-2', function() {
|
||||
this.expect(foo).toEqual(2);
|
||||
expect(foo).toEqual(2);
|
||||
});
|
||||
});
|
||||
|
||||
env.describe('suite 2', function () {
|
||||
env.describe('suite 2', function() {
|
||||
env.it('test 2-1', function() {
|
||||
this.expect(foo).toEqual(1);
|
||||
expect(foo).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
env.currentRunner().execute();
|
||||
|
||||
var runnerResults = env.currentRunner().results();
|
||||
expect(runnerResults.totalCount).toEqual(3);
|
||||
expect(runnerResults.passedCount).toEqual(3);
|
||||
});
|
||||
|
||||
it('should run after a failing spec', function () {
|
||||
var afterEach = originalJasmine.createSpy();
|
||||
env.afterEach(afterEach);
|
||||
|
||||
env.describe('suite', function () {
|
||||
env.it('fails', function () {
|
||||
this.explodes();
|
||||
env.describe('suite',function() {
|
||||
env.it('fails', function() {
|
||||
this.fail();
|
||||
});
|
||||
}).execute();
|
||||
|
||||
@@ -120,103 +98,32 @@ describe('RunnerTest', function() {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should run child suites and specs and generate results when execute is called', function() {
|
||||
env.describe('one suite description', function () {
|
||||
env.it('should be a test', function() {
|
||||
this.runs(function () {
|
||||
this.expect(true).toEqual(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
env.describe('another suite description', function () {
|
||||
env.it('should be another test', function() {
|
||||
this.runs(function () {
|
||||
this.expect(true).toEqual(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
env.currentRunner().execute();
|
||||
|
||||
var runnerResults = env.currentRunner().results();
|
||||
expect(runnerResults.totalCount).toEqual(2);
|
||||
expect(runnerResults.passedCount).toEqual(1);
|
||||
expect(runnerResults.failedCount).toEqual(1);
|
||||
});
|
||||
|
||||
|
||||
it('should ignore suites that have been x\'d', function() {
|
||||
env.xdescribe('one suite description', function () {
|
||||
env.it('should be a test', function() {
|
||||
this.runs(function () {
|
||||
this.expect(true).toEqual(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
env.describe('another suite description', function () {
|
||||
env.it('should be another test', function() {
|
||||
this.runs(function () {
|
||||
this.expect(true).toEqual(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
var disabledDescribe = jasmine.createSpy('xdescribe');
|
||||
env.xdescribe('one suite description', disabledDescribe);
|
||||
env.currentRunner().execute();
|
||||
|
||||
var runnerResults = env.currentRunner().results();
|
||||
expect(runnerResults.totalCount).toEqual(1);
|
||||
expect(runnerResults.passedCount).toEqual(0);
|
||||
expect(runnerResults.failedCount).toEqual(1);
|
||||
expect(disabledDescribe).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should roll up results from all specs', function() {
|
||||
env.describe('one suite description', function () {
|
||||
env.it('should be a test', function() {
|
||||
this.runs(function () {
|
||||
this.expect(true).toEqual(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
env.describe('another suite description', function () {
|
||||
env.it('should be another test', function() {
|
||||
this.runs(function () {
|
||||
this.expect(true).toEqual(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
env.currentRunner().execute();
|
||||
|
||||
var results = env.currentRunner().results();
|
||||
expect(results.totalCount).toEqual(2);
|
||||
expect(results.passedCount).toEqual(1);
|
||||
expect(results.failedCount).toEqual(1);
|
||||
});
|
||||
|
||||
describe('reporting', function () {
|
||||
describe('reporting', function() {
|
||||
var fakeReporter;
|
||||
beforeEach(function () {
|
||||
fakeReporter = originalJasmine.createSpyObj("fakeReporter", ["log", "reportRunnerStarting", "reportRunnerResults"]);
|
||||
env.addReporter(fakeReporter);
|
||||
});
|
||||
|
||||
it('should report runner results when the runner has completed running', function() {
|
||||
env.describe('one suite description', function () {
|
||||
env.describe('one suite description', function() {
|
||||
env.it('should be a test', function() {
|
||||
this.runs(function () {
|
||||
this.runs(function() {
|
||||
this.expect(true).toEqual(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
env.describe('another suite description', function () {
|
||||
env.describe('another suite description', function() {
|
||||
env.it('should be another test', function() {
|
||||
this.waits(200);
|
||||
this.runs(function () {
|
||||
this.runs(function() {
|
||||
this.expect(true).toEqual(false);
|
||||
});
|
||||
});
|
||||
@@ -225,10 +132,7 @@ describe('RunnerTest', function() {
|
||||
env.currentRunner().execute();
|
||||
expect(fakeReporter.reportRunnerResults).not.toHaveBeenCalled();
|
||||
fakeTimer.tick(200);
|
||||
//This blows up the JSApiReporter.
|
||||
//expect(fakeReporter.reportRunnerResults).toHaveBeenCalledWith(env.currentRunner);
|
||||
expect(fakeReporter.reportRunnerResults).toHaveBeenCalled();
|
||||
expect(fakeReporter.reportRunnerResults.mostRecentCall.args[0].results()).toEqual(env.currentRunner().results());
|
||||
expect(fakeReporter.reportRunnerResults).toHaveBeenCalledWith(env.currentRunner());
|
||||
});
|
||||
});
|
||||
|
||||
@@ -264,7 +168,8 @@ describe('RunnerTest', function() {
|
||||
suite2 = env.describe("suite 2", function() {
|
||||
});
|
||||
});
|
||||
suite3 = env.describe("suite 3", function() {});
|
||||
suite3 = env.describe("suite 3", function() {
|
||||
});
|
||||
});
|
||||
|
||||
it("#suites should return a flat array of all suites, including nested suites", function() {
|
||||
|
||||
@@ -576,66 +576,6 @@ describe("jasmine spec running", function () {
|
||||
|
||||
});
|
||||
|
||||
it("testBeforeAndAfterCallbacks", function () {
|
||||
var suiteWithBefore = env.describe('one suite with a before', function () {
|
||||
|
||||
this.beforeEach(function () {
|
||||
this.foo = 1;
|
||||
});
|
||||
|
||||
env.it('should be a spec', function () {
|
||||
this.runs(function() {
|
||||
this.foo++;
|
||||
this.expect(this.foo).toEqual(2);
|
||||
});
|
||||
});
|
||||
|
||||
env.it('should be another spec', function () {
|
||||
this.runs(function() {
|
||||
this.foo++;
|
||||
this.expect(this.foo).toEqual(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suiteWithBefore.execute();
|
||||
|
||||
var suite = suiteWithBefore;
|
||||
|
||||
expect(suite.results().getItems()[0].passed()).toEqual(true); // "testBeforeAndAfterCallbacks: the first spec's foo should have been 2");
|
||||
expect(suite.results().getItems()[1].passed()).toEqual(true); // "testBeforeAndAfterCallbacks: the second spec's this.foo should have been 2");
|
||||
|
||||
|
||||
var foo = 1;
|
||||
var suiteWithAfter = env.describe('one suite with an after_each', function () {
|
||||
|
||||
env.it('should be a spec with an after_each', function () {
|
||||
this.expect(foo).toEqual(1);
|
||||
foo++;
|
||||
this.expect(foo).toEqual(2);
|
||||
});
|
||||
|
||||
env.it('should be another spec with an after_each', function () {
|
||||
this.expect(foo).toEqual(0);
|
||||
foo++;
|
||||
this.expect(foo).toEqual(1);
|
||||
});
|
||||
|
||||
this.afterEach(function () {
|
||||
foo = 0;
|
||||
});
|
||||
});
|
||||
|
||||
suiteWithAfter.execute();
|
||||
|
||||
suite = suiteWithAfter;
|
||||
expect(suite.afterEach.length).toEqual(1);
|
||||
expect(suite.results().getItems()[0].passed()).toEqual(true);
|
||||
expect(suite.results().getItems()[1].passed()).toEqual(true);
|
||||
expect(foo).toEqual(0);
|
||||
|
||||
});
|
||||
|
||||
it('#waits should allow consecutive waits calls', function () {
|
||||
var foo = 0;
|
||||
var waitsSuite = env.describe('suite that waits', function () {
|
||||
@@ -873,85 +813,6 @@ describe("jasmine spec running", function () {
|
||||
expect(secondSpecHasRun).toEqual(true);
|
||||
});
|
||||
|
||||
it("testBeforeExecutesSafely", function() {
|
||||
var report = "";
|
||||
var suite = env.describe('before fails on first test, passes on second', function() {
|
||||
var counter = 0;
|
||||
this.beforeEach(function() {
|
||||
counter++;
|
||||
if (counter == 1) {
|
||||
throw "before failure";
|
||||
}
|
||||
});
|
||||
env.it("first should not run because before fails", function() {
|
||||
this.runs(function() {
|
||||
report += "first";
|
||||
this.expect(true).toEqual(true);
|
||||
});
|
||||
});
|
||||
env.it("second should run and pass because before passes", function() {
|
||||
this.runs(function() {
|
||||
report += "second";
|
||||
this.expect(true).toEqual(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite.execute();
|
||||
|
||||
expect(report).toEqual("firstsecond");
|
||||
var suiteResults = suite.results();
|
||||
expect(suiteResults.getItems()[0].getItems()[0].passed).toEqual(false);
|
||||
expect(suiteResults.getItems()[1].getItems()[0].passed).toEqual(true);
|
||||
});
|
||||
|
||||
it("testAfterExecutesSafely", function() {
|
||||
var report = "";
|
||||
var suite = env.describe('after fails on first test, then passes', function() {
|
||||
var counter = 0;
|
||||
this.afterEach(function() {
|
||||
counter++;
|
||||
if (counter == 1) {
|
||||
throw "after failure";
|
||||
}
|
||||
});
|
||||
env.it("first should run, expectation passes, but spec fails because after fails", function() {
|
||||
this.runs(function() {
|
||||
report += "first";
|
||||
this.expect(true).toEqual(true);
|
||||
});
|
||||
});
|
||||
env.it("second should run and pass because after passes", function() {
|
||||
this.runs(function() {
|
||||
report += "second";
|
||||
this.expect(true).toEqual(true);
|
||||
});
|
||||
});
|
||||
env.it("third should run and pass because after passes", function() {
|
||||
this.runs(function() {
|
||||
report += "third";
|
||||
this.expect(true).toEqual(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite.execute();
|
||||
|
||||
expect(report).toEqual("firstsecondthird"); // "all tests should run");
|
||||
//After each errors should not go in spec results because it confuses the count.
|
||||
var suiteResults = suite.results();
|
||||
expect(suiteResults.getItems().length).toEqual(3, 'testAfterExecutesSafely should have results for three specs');
|
||||
|
||||
expect(suiteResults.getItems()[0].getItems()[0].passed).toEqual(true, "testAfterExecutesSafely 1st spec should pass");
|
||||
expect(suiteResults.getItems()[1].getItems()[0].passed).toEqual(true, "testAfterExecutesSafely 2nd spec should pass");
|
||||
expect(suiteResults.getItems()[2].getItems()[0].passed).toEqual(true, "testAfterExecutesSafely 3rd spec should pass");
|
||||
|
||||
expect(suiteResults.getItems()[0].getItems()[0].passed).toEqual(true, "testAfterExecutesSafely 1st result for 1st suite spec should pass");
|
||||
expect(suiteResults.getItems()[0].getItems()[1].passed).toEqual(false, "testAfterExecutesSafely 2nd result for 1st suite spec should fail because afterEach failed");
|
||||
expect(suiteResults.getItems()[1].getItems()[0].passed).toEqual(true, "testAfterExecutesSafely 2nd suite spec should pass");
|
||||
expect(suiteResults.getItems()[2].getItems()[0].passed).toEqual(true, "testAfterExecutesSafely 3rd suite spec should pass");
|
||||
});
|
||||
|
||||
it("should permit nested describes", function() {
|
||||
var actions = [];
|
||||
|
||||
@@ -1115,101 +976,36 @@ describe("jasmine spec running", function () {
|
||||
expect(nestedSpec.getFullName()).toEqual('Test Subject when under circumstance A and circumstance B behaves thusly.'); //, "Spec.fullName was incorrect: " + nestedSpec.getFullName());
|
||||
});
|
||||
|
||||
it("should skip empty suites", function () {
|
||||
env.describe('NonEmptySuite1', function() {
|
||||
env.it('should pass', function() {
|
||||
this.expect(true).toEqual(true);
|
||||
});
|
||||
env.describe('NestedEmptySuite', function() {
|
||||
});
|
||||
env.it('should pass', function() {
|
||||
this.expect(true).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
env.describe('EmptySuite', function() {
|
||||
});
|
||||
|
||||
env.describe('NonEmptySuite2', function() {
|
||||
env.it('should pass', function() {
|
||||
this.expect(true).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
env.execute();
|
||||
|
||||
var runnerResults = env.currentRunner_.results();
|
||||
expect(runnerResults.totalCount).toEqual(3);
|
||||
expect(runnerResults.passedCount).toEqual(3);
|
||||
expect(runnerResults.failedCount).toEqual(0);
|
||||
});
|
||||
|
||||
it("should bind 'this' to the running spec within the spec body", function() {
|
||||
var spec;
|
||||
var suite = env.describe('one suite description', function () {
|
||||
env.it('should be a test with queuedFunctions', function() {
|
||||
spec = this.runs(function() {
|
||||
var specExecuted = jasmine.createSpy(), spec;
|
||||
|
||||
env.describe('Test Subject', function() {
|
||||
spec = env.it('should be a test with queuedFunctions', function() {
|
||||
this.runs(function() {
|
||||
this.foo = 0;
|
||||
expect(this.foo).toBe(0);
|
||||
specExecuted();
|
||||
});
|
||||
|
||||
this.runs(function() {
|
||||
this.foo++;
|
||||
});
|
||||
|
||||
this.runs(function() {
|
||||
var that = this;
|
||||
fakeTimer.setTimeout(function() {
|
||||
that.foo++;
|
||||
}, 250);
|
||||
});
|
||||
|
||||
this.runs(function() {
|
||||
this.expect(this.foo).toEqual(2);
|
||||
});
|
||||
|
||||
this.waits(300);
|
||||
|
||||
this.runs(function() {
|
||||
this.expect(this.foo).toEqual(2);
|
||||
expect(this.foo).toBe(1);
|
||||
specExecuted();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
suite.execute();
|
||||
fakeTimer.tick(600);
|
||||
expect(spec.foo).toEqual(2);
|
||||
var suiteResults = suite.results();
|
||||
expect(suiteResults.getItems()[0].getItems().length).toEqual(2);
|
||||
expect(suiteResults.getItems()[0].getItems()[0].passed).toEqual(false);
|
||||
expect(suiteResults.getItems()[0].getItems()[1].passed).toEqual(true);
|
||||
spec.execute();
|
||||
expect(specExecuted.callCount).toBe(2);
|
||||
});
|
||||
|
||||
it("shouldn't run disabled tests", function() {
|
||||
var xitSpecWasRun = false;
|
||||
var suite = env.describe('default current suite', function() {
|
||||
env.xit('disabled spec').runs(function () {
|
||||
xitSpecWasRun = true;
|
||||
});
|
||||
|
||||
env.it('enabled spec').runs(function () {
|
||||
var foo = 'bar';
|
||||
expect(foo).toEqual('bar');
|
||||
});
|
||||
var disabledSpec = originalJasmine.createSpy('disabledSpec'),
|
||||
suite = env.describe('default current suite', function() {
|
||||
env.xit('disabled spec').runs(disabledSpec);
|
||||
});
|
||||
|
||||
suite.execute();
|
||||
expect(xitSpecWasRun).toEqual(false);
|
||||
});
|
||||
|
||||
it('shouldn\'t execute specs in disabled suites', function() {
|
||||
var spy = originalJasmine.createSpy();
|
||||
var disabledSuite = env.xdescribe('a disabled suite', function() {
|
||||
env.it('enabled spec, but should not be run', function() {
|
||||
spy();
|
||||
});
|
||||
});
|
||||
|
||||
disabledSuite.execute();
|
||||
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
expect(disabledSpec).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('#explodes should throw an exception when it is called inside a spec', function() {
|
||||
|
||||
@@ -1,239 +0,0 @@
|
||||
describe("TrivialReporter", function() {
|
||||
var env;
|
||||
var trivialReporter;
|
||||
var body;
|
||||
var fakeDocument;
|
||||
|
||||
beforeEach(function() {
|
||||
env = new jasmine.Env();
|
||||
env.updateInterval = 0;
|
||||
|
||||
body = document.createElement("body");
|
||||
fakeDocument = { body: body, location: { search: "" } };
|
||||
trivialReporter = new jasmine.TrivialReporter(fakeDocument);
|
||||
});
|
||||
|
||||
function fakeSpec(name) {
|
||||
return {
|
||||
getFullName: function() {
|
||||
return name;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function findElements(divs, withClass) {
|
||||
var els = [];
|
||||
for (var i = 0; i < divs.length; i++) {
|
||||
if (divs[i].className == withClass) els.push(divs[i]);
|
||||
}
|
||||
return els;
|
||||
}
|
||||
|
||||
function findElement(divs, withClass) {
|
||||
var els = findElements(divs, withClass);
|
||||
if (els.length > 0) {
|
||||
return els[0];
|
||||
}
|
||||
throw new Error("couldn't find div with class " + withClass);
|
||||
}
|
||||
|
||||
it("should run only specs beginning with spec parameter", function() {
|
||||
fakeDocument.location.search = "?spec=run%20this";
|
||||
expect(trivialReporter.specFilter(fakeSpec("run this"))).toBeTruthy();
|
||||
expect(trivialReporter.specFilter(fakeSpec("not the right spec"))).toBeFalsy();
|
||||
expect(trivialReporter.specFilter(fakeSpec("not run this"))).toBeFalsy();
|
||||
});
|
||||
|
||||
it("should display empty divs for every suite when the runner is starting", function() {
|
||||
trivialReporter.reportRunnerStarting({
|
||||
env: env,
|
||||
suites: function() {
|
||||
return [ new jasmine.Suite({}, "suite 1", null, null) ];
|
||||
}
|
||||
});
|
||||
|
||||
var divs = findElements(body.getElementsByTagName("div"), "suite");
|
||||
expect(divs.length).toEqual(1);
|
||||
expect(divs[0].innerHTML).toContain("suite 1");
|
||||
});
|
||||
|
||||
describe('Matcher reporting', function () {
|
||||
var getResultMessageDiv = function (body) {
|
||||
var divs = body.getElementsByTagName("div");
|
||||
for (var i = 0; i < divs.length; i++) {
|
||||
if (divs[i].className.match(/resultMessage/)) {
|
||||
return divs[i];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var runner, spec, fakeTimer;
|
||||
beforeEach(function () {
|
||||
fakeTimer = new originalJasmine.FakeTimer();
|
||||
env.setTimeout = fakeTimer.setTimeout;
|
||||
env.clearTimeout = fakeTimer.clearTimeout;
|
||||
env.setInterval = fakeTimer.setInterval;
|
||||
env.clearInterval = fakeTimer.clearInterval;
|
||||
runner = env.currentRunner();
|
||||
var suite = new jasmine.Suite(env, 'some suite');
|
||||
runner.add(suite);
|
||||
spec = new jasmine.Spec(env, suite, 'some spec');
|
||||
suite.add(spec);
|
||||
fakeDocument.location.search = "?";
|
||||
env.addReporter(trivialReporter);
|
||||
});
|
||||
|
||||
describe('toContain', function () {
|
||||
it('should show actual and expected', function () {
|
||||
spec.runs(function () {
|
||||
this.expect('foo').toContain('bar');
|
||||
});
|
||||
runner.execute();
|
||||
fakeTimer.tick(0);
|
||||
|
||||
var resultEl = getResultMessageDiv(body);
|
||||
expect(resultEl.innerHTML).toMatch(/foo/);
|
||||
expect(resultEl.innerHTML).toMatch(/bar/);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("failure messages (integration)", function () {
|
||||
var spec, results, expectationResult;
|
||||
|
||||
beforeEach(function() {
|
||||
results = {
|
||||
passed: function() {
|
||||
return false;
|
||||
},
|
||||
getItems: function() {
|
||||
}};
|
||||
|
||||
var suite1 = new jasmine.Suite(env, "suite 1", null, null);
|
||||
|
||||
spec = {
|
||||
suite: suite1,
|
||||
getFullName: function() {
|
||||
return "foo";
|
||||
},
|
||||
results: function() {
|
||||
return results;
|
||||
}
|
||||
};
|
||||
|
||||
trivialReporter.reportRunnerStarting({
|
||||
env: env,
|
||||
suites: function() {
|
||||
return [ suite1 ];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("should add the failure message to the DOM (non-toEquals matchers)", function() {
|
||||
expectationResult = jasmine.buildExpectationResult({
|
||||
matcherName: "toBeNull", passed: false, message: "Expected 'a' to be null, but it was not"
|
||||
});
|
||||
|
||||
spyOn(results, 'getItems').andReturn([expectationResult]);
|
||||
|
||||
trivialReporter.reportSpecResults(spec);
|
||||
|
||||
var divs = body.getElementsByTagName("div");
|
||||
var errorDiv = findElement(divs, 'resultMessage fail');
|
||||
expect(errorDiv.innerHTML).toEqual("Expected 'a' to be null, but it was not");
|
||||
});
|
||||
|
||||
it("should add the failure message to the DOM (non-toEquals matchers) html escaping", function() {
|
||||
expectationResult = jasmine.buildExpectationResult({
|
||||
matcherName: "toBeNull", passed: false, message: "Expected '1 < 2' to <b>e null, & it was not"
|
||||
});
|
||||
|
||||
spyOn(results, 'getItems').andReturn([expectationResult]);
|
||||
|
||||
trivialReporter.reportSpecResults(spec);
|
||||
|
||||
var divs = body.getElementsByTagName("div");
|
||||
var errorDiv = findElement(divs, 'resultMessage fail');
|
||||
expect(errorDiv.innerHTML).toEqual("Expected '1 < 2' to <b>e null, & it was not");
|
||||
});
|
||||
});
|
||||
|
||||
describe("log messages", function() {
|
||||
it("should appear in the report", function() {
|
||||
env.describe("suite", function() {
|
||||
env.it("will have log messages", function() {
|
||||
this.log("this is a", "multipart log message");
|
||||
});
|
||||
});
|
||||
|
||||
env.addReporter(trivialReporter);
|
||||
env.execute();
|
||||
|
||||
var divs = body.getElementsByTagName("div");
|
||||
var errorDiv = findElement(divs, 'resultMessage log');
|
||||
expect(errorDiv.innerHTML).toEqual("this is a multipart log message");
|
||||
});
|
||||
|
||||
xit("should work on IE without console.log.apply", function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("duplicate example names", function() {
|
||||
it("should report failures correctly", function() {
|
||||
var suite1 = env.describe("suite", function() {
|
||||
env.it("will have log messages", function() {
|
||||
this.log("this one fails!");
|
||||
this.expect(true).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
var suite2 = env.describe("suite", function() {
|
||||
env.it("will have log messages", function() {
|
||||
this.log("this one passes!");
|
||||
this.expect(true).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
env.addReporter(trivialReporter);
|
||||
env.execute();
|
||||
|
||||
var divs = body.getElementsByTagName("div");
|
||||
var passedSpecDiv = findElement(divs, 'suite passed');
|
||||
expect(passedSpecDiv.className).toEqual('suite passed');
|
||||
expect(passedSpecDiv.innerHTML).toContain("this one passes!");
|
||||
expect(passedSpecDiv.innerHTML).not.toContain("this one fails!");
|
||||
|
||||
var failedSpecDiv = findElement(divs, 'suite failed');
|
||||
expect(failedSpecDiv.className).toEqual('suite failed');
|
||||
expect(failedSpecDiv.innerHTML).toContain("this one fails!");
|
||||
expect(failedSpecDiv.innerHTML).not.toContain("this one passes!");
|
||||
});
|
||||
});
|
||||
|
||||
describe('#reportSpecStarting', function() {
|
||||
var spec1;
|
||||
beforeEach(function () {
|
||||
env.describe("suite 1", function() {
|
||||
spec1 = env.it("spec 1", function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('DOES NOT log running specs by default', function() {
|
||||
spyOn(trivialReporter, 'log');
|
||||
|
||||
trivialReporter.reportSpecStarting(spec1);
|
||||
|
||||
expect(trivialReporter.log).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('logs running specs when log_running_specs is true', function() {
|
||||
trivialReporter.logRunningSpecs = true;
|
||||
spyOn(trivialReporter, 'log');
|
||||
|
||||
trivialReporter.reportSpecStarting(spec1);
|
||||
|
||||
expect(trivialReporter.log).toHaveBeenCalledWith('>> Jasmine Running suite 1 spec 1...');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -21,7 +21,6 @@
|
||||
<script type="text/javascript" src=".././src/html/ReporterView.js"></script>
|
||||
<script type="text/javascript" src=".././src/html/SpecView.js"></script>
|
||||
<script type="text/javascript" src=".././src/html/SuiteView.js"></script>
|
||||
<script type="text/javascript" src=".././src/html/TrivialReporter.js"></script>
|
||||
<script type="text/javascript" src=".././src/console/ConsoleReporter.js"></script>
|
||||
|
||||
<!-- include spec files here... -->
|
||||
@@ -48,7 +47,6 @@
|
||||
<script type="text/javascript" src=".././spec/html/HTMLReporterSpec.js"></script>
|
||||
<script type="text/javascript" src=".././spec/html/MatchersHtmlSpec.js"></script>
|
||||
<script type="text/javascript" src=".././spec/html/PrettyPrintHtmlSpec.js"></script>
|
||||
<script type="text/javascript" src=".././spec/html/TrivialReporterSpec.js"></script>
|
||||
<script type="text/javascript" src=".././spec/console/ConsoleReporterSpec.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
Reference in New Issue
Block a user